home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources / combine.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-14  |  316.3 KB  |  9,639 lines  |  [TEXT/MPS ]

  1. /* Optimize by combining instructions for GNU compiler.
  2.    Copyright (C) 1987, 1988, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This module is essentially the "combiner" phase of the U. of Arizona
  22.    Portable Optimizer, but redone to work on our list-structured
  23.    representation for RTL instead of their string representation.
  24.  
  25.    The LOG_LINKS of each insn identify the most recent assignment
  26.    to each REG used in the insn.  It is a list of previous insns,
  27.    each of which contains a SET for a REG that is used in this insn
  28.    and not used or set in between.  LOG_LINKs never cross basic blocks.
  29.    They were set up by the preceding pass (lifetime analysis).
  30.  
  31.    We try to combine each pair of insns joined by a logical link.
  32.    We also try to combine triples of insns A, B and C when
  33.    C has a link back to B and B has a link back to A.
  34.  
  35.    LOG_LINKS does not have links for use of the CC0.  They don't
  36.    need to, because the insn that sets the CC0 is always immediately
  37.    before the insn that tests it.  So we always regard a branch
  38.    insn as having a logical link to the preceding insn.  The same is true
  39.    for an insn explicitly using CC0.
  40.  
  41.    We check (with use_crosses_set_p) to avoid combining in such a way
  42.    as to move a computation to a place where its value would be different.
  43.  
  44.    Combination is done by mathematically substituting the previous
  45.    insn(s) values for the regs they set into the expressions in
  46.    the later insns that refer to these regs.  If the result is a valid insn
  47.    for our target machine, according to the machine description,
  48.    we install it, delete the earlier insns, and update the data flow
  49.    information (LOG_LINKS and REG_NOTES) for what we did.
  50.  
  51.    There are a few exceptions where the dataflow information created by
  52.    flow.c aren't completely updated:
  53.  
  54.    - reg_live_length is not updated
  55.    - reg_n_refs is not adjusted in the rare case when a register is
  56.      no longer required in a computation
  57.    - there are extremely rare cases (see distribute_regnotes) when a
  58.      REG_DEAD note is lost
  59.    - a LOG_LINKS entry that refers to an insn with multiple SETs may be
  60.      removed because there is no way to know which register it was 
  61.      linking
  62.  
  63.    To simplify substitution, we combine only when the earlier insn(s)
  64.    consist of only a single assignment.  To simplify updating afterward,
  65.    we never combine when a subroutine call appears in the middle.
  66.  
  67.    Since we do not represent assignments to CC0 explicitly except when that
  68.    is all an insn does, there is no LOG_LINKS entry in an insn that uses
  69.    the condition code for the insn that set the condition code.
  70.    Fortunately, these two insns must be consecutive.
  71.    Therefore, every JUMP_INSN is taken to have an implicit logical link
  72.    to the preceding insn.  This is not quite right, since non-jumps can
  73.    also use the condition code; but in practice such insns would not
  74.    combine anyway.  */
  75.  
  76. #include "config.h"
  77. #include "gvarargs.h"
  78. #include "rtl.h"
  79. #include "flags.h"
  80. #include "regs.h"
  81. #include "expr.h"
  82. #include "basic-block.h"
  83. #include "insn-config.h"
  84. #include "insn-flags.h"
  85. #include "insn-codes.h"
  86. #include "insn-attr.h"
  87. #include "recog.h"
  88. #include "real.h"
  89. #include <stdio.h>
  90.  
  91. /* It is not safe to use ordinary gen_lowpart in combine.
  92.    Use gen_lowpart_for_combine instead.  See comments there.  */
  93. #define gen_lowpart dont_use_gen_lowpart_you_dummy
  94.  
  95. /* Number of attempts to combine instructions in this function.  */
  96.  
  97. static int combine_attempts;
  98.  
  99. /* Number of attempts that got as far as substitution in this function.  */
  100.  
  101. static int combine_merges;
  102.  
  103. /* Number of instructions combined with added SETs in this function.  */
  104.  
  105. static int combine_extras;
  106.  
  107. /* Number of instructions combined in this function.  */
  108.  
  109. static int combine_successes;
  110.  
  111. /* Totals over entire compilation.  */
  112.  
  113. static int total_attempts, total_merges, total_extras, total_successes;
  114.  
  115. /* Vector mapping INSN_UIDs to cuids.
  116.    The cuids are like uids but increase monotonically always.
  117.    Combine always uses cuids so that it can compare them.
  118.    But actually renumbering the uids, which we used to do,
  119.    proves to be a bad idea because it makes it hard to compare
  120.    the dumps produced by earlier passes with those from later passes.  */
  121.  
  122. static int *uid_cuid;
  123.  
  124. /* Get the cuid of an insn.  */
  125.  
  126. #define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)])
  127.  
  128. /* Maximum register number, which is the size of the tables below.  */
  129.  
  130. static int combine_max_regno;
  131.  
  132. /* Record last point of death of (hard or pseudo) register n.  */
  133.  
  134. static rtx *reg_last_death;
  135.  
  136. /* Record last point of modification of (hard or pseudo) register n.  */
  137.  
  138. static rtx *reg_last_set;
  139.  
  140. /* Record the cuid of the last insn that invalidated memory
  141.    (anything that writes memory, and subroutine calls, but not pushes).  */
  142.  
  143. static int mem_last_set;
  144.  
  145. /* Record the cuid of the last CALL_INSN
  146.    so we can tell whether a potential combination crosses any calls.  */
  147.  
  148. static int last_call_cuid;
  149.  
  150. /* When `subst' is called, this is the insn that is being modified
  151.    (by combining in a previous insn).  The PATTERN of this insn
  152.    is still the old pattern partially modified and it should not be
  153.    looked at, but this may be used to examine the successors of the insn
  154.    to judge whether a simplification is valid.  */
  155.  
  156. static rtx subst_insn;
  157.  
  158. /* This is the lowest CUID that `subst' is currently dealing with.
  159.    get_last_value will not return a value if the register was set at or
  160.    after this CUID.  If not for this mechanism, we could get confused if
  161.    I2 or I1 in try_combine were an insn that used the old value of a register
  162.    to obtain a new value.  In that case, we might erroneously get the
  163.    new value of the register when we wanted the old one.  */
  164.  
  165. static int subst_low_cuid;
  166.  
  167. /* This is the value of undobuf.num_undo when we started processing this 
  168.    substitution.  This will prevent gen_rtx_combine from re-used a piece
  169.    from the previous expression.  Doing so can produce circular rtl
  170.    structures.  */
  171.  
  172. static int previous_num_undos;
  173.  
  174. /* The next group of arrays allows the recording of the last value assigned
  175.    to (hard or pseudo) register n.  We use this information to see if a
  176.    operation being processed is redundant given a prior operation performed
  177.    on the register.  For example, an `and' with a constant is redundant if
  178.    all the zero bits are already known to be turned off.
  179.  
  180.    We use an approach similar to that used by cse, but change it in the
  181.    following ways:
  182.  
  183.    (1) We do not want to reinitialize at each label.
  184.    (2) It is useful, but not critical, to know the actual value assigned
  185.        to a register.  Often just its form is helpful.
  186.  
  187.    Therefore, we maintain the following arrays:
  188.  
  189.    reg_last_set_value        the last value assigned
  190.    reg_last_set_label        records the value of label_tick when the
  191.                 register was assigned
  192.    reg_last_set_table_tick    records the value of label_tick when a
  193.                 value using the register is assigned
  194.    reg_last_set_invalid        set to non-zero when it is not valid
  195.                 to use the value of this register in some
  196.                 register's value
  197.  
  198.    To understand the usage of these tables, it is important to understand
  199.    the distinction between the value in reg_last_set_value being valid
  200.    and the register being validly contained in some other expression in the
  201.    table.
  202.  
  203.    Entry I in reg_last_set_value is valid if it is non-zero, and either
  204.    reg_n_sets[i] is 1 or reg_last_set_label[i] == label_tick.
  205.  
  206.    Register I may validly appear in any expression returned for the value
  207.    of another register if reg_n_sets[i] is 1.  It may also appear in the
  208.    value for register J if reg_last_set_label[i] < reg_last_set_label[j] or
  209.    reg_last_set_invalid[j] is zero.
  210.  
  211.    If an expression is found in the table containing a register which may
  212.    not validly appear in an expression, the register is replaced by
  213.    something that won't match, (clobber (const_int 0)).
  214.  
  215.    reg_last_set_invalid[i] is set non-zero when register I is being assigned
  216.    to and reg_last_set_table_tick[i] == label_tick.  */
  217.  
  218. /* Record last value assigned to (hard or pseudo) register n. */
  219.  
  220. static rtx *reg_last_set_value;
  221.  
  222. /* Record the value of label_tick when the value for register n is placed in
  223.    reg_last_set_value[n].  */
  224.  
  225. static short *reg_last_set_label;
  226.  
  227. /* Record the value of label_tick when an expression involving register n
  228.    is placed in reg_last_set_value. */
  229.  
  230. static short *reg_last_set_table_tick;
  231.  
  232. /* Set non-zero if references to register n in expressions should not be
  233.    used.  */
  234.  
  235. static char *reg_last_set_invalid;
  236.  
  237. /* Incremented for each label. */
  238.  
  239. static short label_tick;
  240.  
  241. /* Some registers that are set more than once and used in more than one
  242.    basic block are nevertheless always set in similar ways.  For example,
  243.    a QImode register may be loaded from memory in two places on a machine
  244.    where byte loads zero extend.
  245.  
  246.    We record in the following array what we know about the significant
  247.    bits of a register, specifically which bits are known to be zero.
  248.  
  249.    If an entry is zero, it means that we don't know anything special.  */
  250.  
  251. static HOST_WIDE_INT *reg_significant;
  252.  
  253. /* Mode used to compute significance in reg_significant.  It is the largest
  254.    integer mode that can fit in HOST_BITS_PER_WIDE_INT.  */
  255.  
  256. static enum machine_mode significant_mode;
  257.  
  258. /* Nonzero if we know that a register has some leading bits that are always
  259.    equal to the sign bit.  */
  260.  
  261. static char *reg_sign_bit_copies;
  262.  
  263. /* Nonzero when reg_significant and reg_sign_bit_copies can be safely used.
  264.    It is zero while computing them and after combine has completed.  This
  265.    former test prevents propagating values based on previously set values,
  266.    which can be incorrect if a variable is modified in a loop.  */
  267.  
  268. static int significant_valid;
  269.  
  270. /* Record one modification to rtl structure
  271.    to be undone by storing old_contents into *where.
  272.    is_int is 1 if the contents are an int.  */
  273.  
  274. struct undo
  275. {
  276.   int is_int;
  277.   union {rtx rtx; int i;} old_contents;
  278.   union {rtx *rtx; int *i;} where;
  279. };
  280.  
  281. /* Record a bunch of changes to be undone, up to MAX_UNDO of them.
  282.    num_undo says how many are currently recorded.
  283.  
  284.    storage is nonzero if we must undo the allocation of new storage.
  285.    The value of storage is what to pass to obfree.
  286.  
  287.    other_insn is nonzero if we have modified some other insn in the process
  288.    of working on subst_insn.  It must be verified too.  */
  289.  
  290. #define MAX_UNDO 50
  291.  
  292. struct undobuf
  293. {
  294.   int num_undo;
  295.   char *storage;
  296.   struct undo undo[MAX_UNDO];
  297.   rtx other_insn;
  298. };
  299.  
  300. static struct undobuf undobuf;
  301.  
  302. /* Substitute NEWVAL, an rtx expression, into INTO, a place in some
  303.    insn.  The substitution can be undone by undo_all.  If INTO is already
  304.    set to NEWVAL, do not record this change.  Because computing NEWVAL might
  305.    also call SUBST, we have to compute it before we put anything into
  306.    the undo table.  */
  307.  
  308. #define SUBST(INTO, NEWVAL)  \
  309.  do { rtx _new = (NEWVAL);                        \
  310.       if (undobuf.num_undo < MAX_UNDO)                    \
  311.     {                                \
  312.       undobuf.undo[undobuf.num_undo].is_int = 0;            \
  313.       undobuf.undo[undobuf.num_undo].where.rtx = &INTO;        \
  314.       undobuf.undo[undobuf.num_undo].old_contents.rtx = INTO;    \
  315.       INTO = _new;                            \
  316.       if (undobuf.undo[undobuf.num_undo].old_contents.rtx != INTO)    \
  317.         undobuf.num_undo++;                     \
  318.     }                                \
  319.     } while (0)
  320.  
  321. /* Similar to SUBST, but NEWVAL is an int.  INTO will normally be an XINT
  322.    expression.
  323.    Note that substitution for the value of a CONST_INT is not safe.  */
  324.  
  325. #define SUBST_INT(INTO, NEWVAL)  \
  326.  do { if (undobuf.num_undo < MAX_UNDO)                    \
  327. {                                    \
  328.       undobuf.undo[undobuf.num_undo].is_int = 1;            \
  329.       undobuf.undo[undobuf.num_undo].where.i = (int *) &INTO;    \
  330.       undobuf.undo[undobuf.num_undo].old_contents.i = INTO;        \
  331.       INTO = NEWVAL;                        \
  332.       if (undobuf.undo[undobuf.num_undo].old_contents.i != INTO)    \
  333.         undobuf.num_undo++;                        \
  334.     }                                \
  335.      } while (0)
  336.  
  337. /* Number of times the pseudo being substituted for
  338.    was found and replaced.  */
  339.  
  340. static int n_occurrences;
  341.  
  342. static void set_significant ();
  343. static void move_deaths ();
  344. rtx remove_death ();
  345. static void record_value_for_reg ();
  346. static void record_dead_and_set_regs ();
  347. static int use_crosses_set_p ();
  348. static rtx try_combine ();
  349. static rtx *find_split_point ();
  350. static rtx subst ();
  351. static void undo_all ();
  352. static int reg_dead_at_p ();
  353. static rtx expand_compound_operation ();
  354. static rtx expand_field_assignment ();
  355. static rtx make_extraction ();
  356. static int get_pos_from_mask ();
  357. static rtx force_to_mode ();
  358. static rtx known_cond ();
  359. static rtx make_field_assignment ();
  360. static rtx make_compound_operation ();
  361. static rtx apply_distributive_law ();
  362. static rtx simplify_and_const_int ();
  363. static unsigned HOST_WIDE_INT significant_bits ();
  364. static int num_sign_bit_copies ();
  365. static int merge_outer_ops ();
  366. static rtx simplify_shift_const ();
  367. static int recog_for_combine ();
  368. static rtx gen_lowpart_for_combine ();
  369. static rtx gen_rtx_combine ();
  370. static rtx gen_binary ();
  371. static rtx gen_unary ();
  372. static enum rtx_code simplify_comparison ();
  373. static int reversible_comparison_p ();
  374. static int get_last_value_validate ();
  375. static rtx get_last_value ();
  376. static void distribute_notes ();
  377. static void distribute_links ();
  378.  
  379. /* Main entry point for combiner.  F is the first insn of the function.
  380.    NREGS is the first unused pseudo-reg number.  */
  381.  
  382. void
  383. combine_instructions (f, nregs)
  384.      rtx f;
  385.      int nregs;
  386. {
  387.   register rtx insn, next, prev;
  388.   register int i;
  389.   register rtx links, nextlinks;
  390.  
  391.   combine_attempts = 0;
  392.   combine_merges = 0;
  393.   combine_extras = 0;
  394.   combine_successes = 0;
  395.  
  396.   combine_max_regno = nregs;
  397.  
  398.   reg_last_death = (rtx *) alloca (nregs * sizeof (rtx));
  399.   reg_last_set = (rtx *) alloca (nregs * sizeof (rtx));
  400.   reg_last_set_value = (rtx *) alloca (nregs * sizeof (rtx));
  401.   reg_last_set_table_tick = (short *) alloca (nregs * sizeof (short));
  402.   reg_last_set_label = (short *) alloca (nregs * sizeof (short));
  403.   reg_last_set_invalid = (char *) alloca (nregs * sizeof (char));
  404.   reg_significant = (HOST_WIDE_INT *) alloca (nregs * sizeof (HOST_WIDE_INT));
  405.   reg_sign_bit_copies = (char *) alloca (nregs * sizeof (char));
  406.  
  407.   bzero (reg_last_death, nregs * sizeof (rtx));
  408.   bzero (reg_last_set, nregs * sizeof (rtx));
  409.   bzero (reg_last_set_value, nregs * sizeof (rtx));
  410.   bzero (reg_last_set_table_tick, nregs * sizeof (short));
  411.   bzero (reg_last_set_invalid, nregs * sizeof (char));
  412.   bzero (reg_significant, nregs * sizeof (HOST_WIDE_INT));
  413.   bzero (reg_sign_bit_copies, nregs * sizeof (char));
  414.  
  415.   init_recog_no_volatile ();
  416.  
  417.   /* Compute maximum uid value so uid_cuid can be allocated.  */
  418.  
  419.   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
  420.     if (INSN_UID (insn) > i)
  421.       i = INSN_UID (insn);
  422.  
  423.   uid_cuid = (int *) alloca ((i + 1) * sizeof (int));
  424.  
  425.   significant_mode = mode_for_size (HOST_BITS_PER_WIDE_INT, MODE_INT, 0);
  426.  
  427.   /* Don't use reg_significant when computing it.  This can cause problems
  428.      when, for example, we have j <<= 1 in a loop.  */
  429.  
  430.   significant_valid = 0;
  431.  
  432.   /* Compute the mapping from uids to cuids.
  433.      Cuids are numbers assigned to insns, like uids,
  434.      except that cuids increase monotonically through the code. 
  435.  
  436.      Scan all SETs and see if we can deduce anything about what
  437.      bits are significant for some registers.  */
  438.  
  439.   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
  440.     {
  441.       INSN_CUID (insn) = ++i;
  442.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  443.     note_stores (PATTERN (insn), set_significant);
  444.     }
  445.  
  446.   significant_valid = 1;
  447.  
  448.   /* Now scan all the insns in forward order.  */
  449.  
  450.   label_tick = 1;
  451.   last_call_cuid = 0;
  452.   mem_last_set = 0;
  453.  
  454.   for (insn = f; insn; insn = next ? next : NEXT_INSN (insn))
  455.     {
  456.       next = 0;
  457.  
  458.       if (GET_CODE (insn) == CODE_LABEL)
  459.     label_tick++;
  460.  
  461.       else if (GET_CODE (insn) == INSN
  462.            || GET_CODE (insn) == CALL_INSN
  463.            || GET_CODE (insn) == JUMP_INSN)
  464.     {
  465.       /* Try this insn with each insn it links back to.  */
  466.  
  467.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  468.         if ((next = try_combine (insn, XEXP (links, 0), NULL_RTX)) != 0)
  469.           goto retry;
  470.  
  471.       /* Try each sequence of three linked insns ending with this one.  */
  472.  
  473.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  474.         for (nextlinks = LOG_LINKS (XEXP (links, 0)); nextlinks;
  475.          nextlinks = XEXP (nextlinks, 1))
  476.           if ((next = try_combine (insn, XEXP (links, 0),
  477.                        XEXP (nextlinks, 0))) != 0)
  478.         goto retry;
  479.  
  480. #ifdef HAVE_cc0
  481.       /* Try to combine a jump insn that uses CC0
  482.          with a preceding insn that sets CC0, and maybe with its
  483.          logical predecessor as well.
  484.          This is how we make decrement-and-branch insns.
  485.          We need this special code because data flow connections
  486.          via CC0 do not get entered in LOG_LINKS.  */
  487.  
  488.       if (GET_CODE (insn) == JUMP_INSN
  489.           && (prev = prev_nonnote_insn (insn)) != 0
  490.           && GET_CODE (prev) == INSN
  491.           && sets_cc0_p (PATTERN (prev)))
  492.         {
  493.           if ((next = try_combine (insn, prev, NULL_RTX)) != 0)
  494.         goto retry;
  495.  
  496.           for (nextlinks = LOG_LINKS (prev); nextlinks;
  497.            nextlinks = XEXP (nextlinks, 1))
  498.         if ((next = try_combine (insn, prev,
  499.                      XEXP (nextlinks, 0))) != 0)
  500.           goto retry;
  501.         }
  502.  
  503.       /* Do the same for an insn that explicitly references CC0.  */
  504.       if (GET_CODE (insn) == INSN
  505.           && (prev = prev_nonnote_insn (insn)) != 0
  506.           && GET_CODE (prev) == INSN
  507.           && sets_cc0_p (PATTERN (prev))
  508.           && GET_CODE (PATTERN (insn)) == SET
  509.           && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (insn))))
  510.         {
  511.           if ((next = try_combine (insn, prev, NULL_RTX)) != 0)
  512.         goto retry;
  513.  
  514.           for (nextlinks = LOG_LINKS (prev); nextlinks;
  515.            nextlinks = XEXP (nextlinks, 1))
  516.         if ((next = try_combine (insn, prev,
  517.                      XEXP (nextlinks, 0))) != 0)
  518.           goto retry;
  519.         }
  520.  
  521.       /* Finally, see if any of the insns that this insn links to
  522.          explicitly references CC0.  If so, try this insn, that insn,
  523.          and its predecessor if it sets CC0.  */
  524.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  525.         if (GET_CODE (XEXP (links, 0)) == INSN
  526.         && GET_CODE (PATTERN (XEXP (links, 0))) == SET
  527.         && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (XEXP (links, 0))))
  528.         && (prev = prev_nonnote_insn (XEXP (links, 0))) != 0
  529.         && GET_CODE (prev) == INSN
  530.         && sets_cc0_p (PATTERN (prev))
  531.         && (next = try_combine (insn, XEXP (links, 0), prev)) != 0)
  532.           goto retry;
  533. #endif
  534.  
  535.       /* Try combining an insn with two different insns whose results it
  536.          uses.  */
  537.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  538.         for (nextlinks = XEXP (links, 1); nextlinks;
  539.          nextlinks = XEXP (nextlinks, 1))
  540.           if ((next = try_combine (insn, XEXP (links, 0),
  541.                        XEXP (nextlinks, 0))) != 0)
  542.         goto retry;
  543.  
  544.       if (GET_CODE (insn) != NOTE)
  545.         record_dead_and_set_regs (insn);
  546.  
  547.     retry:
  548.       ;
  549.     }
  550.     }
  551.  
  552.   total_attempts += combine_attempts;
  553.   total_merges += combine_merges;
  554.   total_extras += combine_extras;
  555.   total_successes += combine_successes;
  556.  
  557.   significant_valid = 0;
  558. }
  559.  
  560. /* Called via note_stores.  If X is a pseudo that is used in more than
  561.    one basic block, is narrower that HOST_BITS_PER_WIDE_INT, and is being
  562.    set, record what bits are significant.  If we are clobbering X,
  563.    ignore this "set" because the clobbered value won't be used. 
  564.  
  565.    If we are setting only a portion of X and we can't figure out what
  566.    portion, assume all bits will be used since we don't know what will
  567.    be happening.
  568.  
  569.    Similarly, set how many bits of X are known to be copies of the sign bit
  570.    at all locations in the function.  This is the smallest number implied 
  571.    by any set of X.  */
  572.  
  573. static void
  574. set_significant (x, set)
  575.      rtx x;
  576.      rtx set;
  577. {
  578.   int num;
  579.  
  580.   if (GET_CODE (x) == REG
  581.       && REGNO (x) >= FIRST_PSEUDO_REGISTER
  582.       && reg_n_sets[REGNO (x)] > 1
  583.       && reg_basic_block[REGNO (x)] < 0
  584.       && GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT)
  585.     {
  586.       if (GET_CODE (set) == CLOBBER)
  587.     return;
  588.  
  589.       /* If this is a complex assignment, see if we can convert it into a
  590.      simple assignment.  */
  591.       set = expand_field_assignment (set);
  592.       if (SET_DEST (set) == x)
  593.     {
  594.       reg_significant[REGNO (x)]
  595.         |= significant_bits (SET_SRC (set), significant_mode);
  596.       num = num_sign_bit_copies (SET_SRC (set), GET_MODE (x));
  597.       if (reg_sign_bit_copies[REGNO (x)] == 0
  598.           || reg_sign_bit_copies[REGNO (x)] > num)
  599.         reg_sign_bit_copies[REGNO (x)] = num;
  600.     }
  601.       else
  602.     {
  603.       reg_significant[REGNO (x)] = GET_MODE_MASK (GET_MODE (x));
  604.       reg_sign_bit_copies[REGNO (x)] = 0;
  605.     }
  606.     }
  607. }
  608.  
  609. /* See if INSN can be combined into I3.  PRED and SUCC are optionally
  610.    insns that were previously combined into I3 or that will be combined
  611.    into the merger of INSN and I3.
  612.  
  613.    Return 0 if the combination is not allowed for any reason.
  614.  
  615.    If the combination is allowed, *PDEST will be set to the single 
  616.    destination of INSN and *PSRC to the single source, and this function
  617.    will return 1.  */
  618.  
  619. static int
  620. can_combine_p (insn, i3, pred, succ, pdest, psrc)
  621.      rtx insn;
  622.      rtx i3;
  623.      rtx pred, succ;
  624.      rtx *pdest, *psrc;
  625. {
  626.   int i;
  627.   rtx set = 0, src, dest;
  628.   rtx p, link;
  629.   int all_adjacent = (succ ? (next_active_insn (insn) == succ
  630.                   && next_active_insn (succ) == i3)
  631.               : next_active_insn (insn) == i3);
  632.  
  633.   /* Can combine only if previous insn is a SET of a REG, a SUBREG or CC0.
  634.      or a PARALLEL consisting of such a SET and CLOBBERs. 
  635.  
  636.      If INSN has CLOBBER parallel parts, ignore them for our processing.
  637.      By definition, these happen during the execution of the insn.  When it
  638.      is merged with another insn, all bets are off.  If they are, in fact,
  639.      needed and aren't also supplied in I3, they may be added by
  640.      recog_for_combine.  Otherwise, it won't match. 
  641.  
  642.      We can also ignore a SET whose SET_DEST is mentioned in a REG_UNUSED
  643.      note.
  644.  
  645.      Get the source and destination of INSN.  If more than one, can't 
  646.      combine.  */
  647.      
  648.   if (GET_CODE (PATTERN (insn)) == SET)
  649.     set = PATTERN (insn);
  650.   else if (GET_CODE (PATTERN (insn)) == PARALLEL
  651.        && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
  652.     {
  653.       for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
  654.     {
  655.       rtx elt = XVECEXP (PATTERN (insn), 0, i);
  656.  
  657.       switch (GET_CODE (elt))
  658.         {
  659.           /* We can ignore CLOBBERs.  */
  660.         case CLOBBER:
  661.           break;
  662.  
  663.         case SET:
  664.           /* Ignore SETs whose result isn't used but not those that
  665.          have side-effects.  */
  666.           if (find_reg_note (insn, REG_UNUSED, SET_DEST (elt))
  667.           && ! side_effects_p (elt))
  668.         break;
  669.  
  670.           /* If we have already found a SET, this is a second one and
  671.          so we cannot combine with this insn.  */
  672.           if (set)
  673.         return 0;
  674.  
  675.           set = elt;
  676.           break;
  677.  
  678.         default:
  679.           /* Anything else means we can't combine.  */
  680.           return 0;
  681.         }
  682.     }
  683.  
  684.       if (set == 0
  685.       /* If SET_SRC is an ASM_OPERANDS we can't throw away these CLOBBERs,
  686.          so don't do anything with it.  */
  687.       || GET_CODE (SET_SRC (set)) == ASM_OPERANDS)
  688.     return 0;
  689.     }
  690.   else
  691.     return 0;
  692.  
  693.   if (set == 0)
  694.     return 0;
  695.  
  696.   set = expand_field_assignment (set);
  697.   src = SET_SRC (set), dest = SET_DEST (set);
  698.  
  699.   /* Don't eliminate a store in the stack pointer.  */
  700.   if (dest == stack_pointer_rtx
  701.       /* Don't install a subreg involving two modes not tieable.
  702.      It can worsen register allocation, and can even make invalid reload
  703.      insns, since the reg inside may need to be copied from in the
  704.      outside mode, and that may be invalid if it is an fp reg copied in
  705.      integer mode.  As a special exception, we can allow this if
  706.      I3 is simply copying DEST, a REG,  to CC0.  */
  707.       || (GET_CODE (src) == SUBREG
  708.       && ! MODES_TIEABLE_P (GET_MODE (src), GET_MODE (SUBREG_REG (src)))
  709. #ifdef HAVE_cc0
  710.       && ! (GET_CODE (i3) == INSN && GET_CODE (PATTERN (i3)) == SET
  711.         && SET_DEST (PATTERN (i3)) == cc0_rtx
  712.         && GET_CODE (dest) == REG && dest == SET_SRC (PATTERN (i3)))
  713. #endif
  714.       )
  715.       /* If we couldn't eliminate a field assignment, we can't combine.  */
  716.       || GET_CODE (dest) == ZERO_EXTRACT || GET_CODE (dest) == STRICT_LOW_PART
  717.       /* Don't combine with an insn that sets a register to itself if it has
  718.      a REG_EQUAL note.  This may be part of a REG_NO_CONFLICT sequence.  */
  719.       || (rtx_equal_p (src, dest) && find_reg_note (insn, REG_EQUAL, NULL_RTX))
  720.       /* Can't merge a function call.  */
  721.       || GET_CODE (src) == CALL
  722.       /* Don't substitute into an incremented register.  */
  723.       || FIND_REG_INC_NOTE (i3, dest)
  724.       || (succ && FIND_REG_INC_NOTE (succ, dest))
  725.       /* Don't combine the end of a libcall into anything.  */
  726.       || find_reg_note (insn, REG_RETVAL, NULL_RTX)
  727.       /* Make sure that DEST is not used after SUCC but before I3.  */
  728.       || (succ && ! all_adjacent
  729.       && reg_used_between_p (dest, succ, i3))
  730.       /* Make sure that the value that is to be substituted for the register
  731.      does not use any registers whose values alter in between.  However,
  732.      If the insns are adjacent, a use can't cross a set even though we
  733.      think it might (this can happen for a sequence of insns each setting
  734.      the same destination; reg_last_set of that register might point to
  735.      a NOTE).  Also, don't move a volatile asm across any other insns.  */
  736.       || (! all_adjacent
  737.       && (use_crosses_set_p (src, INSN_CUID (insn))
  738.           || (GET_CODE (src) == ASM_OPERANDS && MEM_VOLATILE_P (src))))
  739.       /* If there is a REG_NO_CONFLICT note for DEST in I3 or SUCC, we get
  740.      better register allocation by not doing the combine.  */
  741.       || find_reg_note (i3, REG_NO_CONFLICT, dest)
  742.       || (succ && find_reg_note (succ, REG_NO_CONFLICT, dest))
  743.       /* Don't combine across a CALL_INSN, because that would possibly
  744.      change whether the life span of some REGs crosses calls or not,
  745.      and it is a pain to update that information.
  746.      Exception: if source is a constant, moving it later can't hurt.
  747.      Accept that special case, because it helps -fforce-addr a lot.  */
  748.       || (INSN_CUID (insn) < last_call_cuid && ! CONSTANT_P (src)))
  749.     return 0;
  750.  
  751.   /* DEST must either be a REG or CC0.  */
  752.   if (GET_CODE (dest) == REG)
  753.     {
  754.       /* If register alignment is being enforced for multi-word items in all
  755.      cases except for parameters, it is possible to have a register copy
  756.      insn referencing a hard register that is not allowed to contain the
  757.      mode being copied and which would not be valid as an operand of most
  758.      insns.  Eliminate this problem by not combining with such an insn.
  759.  
  760.      Also, on some machines we don't want to extend the life of a hard
  761.      register.  */
  762.  
  763.       if (GET_CODE (src) == REG
  764.       && ((REGNO (dest) < FIRST_PSEUDO_REGISTER
  765.            && ! HARD_REGNO_MODE_OK (REGNO (dest), GET_MODE (dest)))
  766. #ifdef SMALL_REGISTER_CLASSES
  767.           /* Don't extend the life of a hard register.  */
  768.           || REGNO (src) < FIRST_PSEUDO_REGISTER
  769. #else
  770.           || (REGNO (src) < FIRST_PSEUDO_REGISTER
  771.           && ! HARD_REGNO_MODE_OK (REGNO (src), GET_MODE (src)))
  772. #endif
  773.       ))
  774.     return 0;
  775.     }
  776.   else if (GET_CODE (dest) != CC0)
  777.     return 0;
  778.  
  779.   /* Don't substitute for a register intended as a clobberable operand.
  780.      Similarly, don't substitute an expression containing a register that
  781.      will be clobbered in I3.  */
  782.   if (GET_CODE (PATTERN (i3)) == PARALLEL)
  783.     for (i = XVECLEN (PATTERN (i3), 0) - 1; i >= 0; i--)
  784.       if (GET_CODE (XVECEXP (PATTERN (i3), 0, i)) == CLOBBER
  785.       && (reg_overlap_mentioned_p (XEXP (XVECEXP (PATTERN (i3), 0, i), 0),
  786.                        src)
  787.           || rtx_equal_p (XEXP (XVECEXP (PATTERN (i3), 0, i), 0), dest)))
  788.     return 0;
  789.  
  790.   /* If INSN contains anything volatile, or is an `asm' (whether volatile
  791.      or not), reject, unless nothing volatile comes between it and I3,
  792.      with the exception of SUCC.  */
  793.  
  794.   if (GET_CODE (src) == ASM_OPERANDS || volatile_refs_p (src))
  795.     for (p = NEXT_INSN (insn); p != i3; p = NEXT_INSN (p))
  796.       if (GET_RTX_CLASS (GET_CODE (p)) == 'i'
  797.       && p != succ && volatile_refs_p (PATTERN (p)))
  798.     return 0;
  799.  
  800.   /* If INSN or I2 contains an autoincrement or autodecrement,
  801.      make sure that register is not used between there and I3,
  802.      and not already used in I3 either.
  803.      Also insist that I3 not be a jump; if it were one
  804.      and the incremented register were spilled, we would lose.  */
  805.  
  806. #ifdef AUTO_INC_DEC
  807.   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  808.     if (REG_NOTE_KIND (link) == REG_INC
  809.     && (GET_CODE (i3) == JUMP_INSN
  810.         || reg_used_between_p (XEXP (link, 0), insn, i3)
  811.         || reg_overlap_mentioned_p (XEXP (link, 0), PATTERN (i3))))
  812.       return 0;
  813. #endif
  814.  
  815. #ifdef HAVE_cc0
  816.   /* Don't combine an insn that follows a CC0-setting insn.
  817.      An insn that uses CC0 must not be separated from the one that sets it.
  818.      We do, however, allow I2 to follow a CC0-setting insn if that insn
  819.      is passed as I1; in that case it will be deleted also.
  820.      We also allow combining in this case if all the insns are adjacent
  821.      because that would leave the two CC0 insns adjacent as well.
  822.      It would be more logical to test whether CC0 occurs inside I1 or I2,
  823.      but that would be much slower, and this ought to be equivalent.  */
  824.  
  825.   p = prev_nonnote_insn (insn);
  826.   if (p && p != pred && GET_CODE (p) == INSN && sets_cc0_p (PATTERN (p))
  827.       && ! all_adjacent)
  828.     return 0;
  829. #endif
  830.  
  831.   /* If we get here, we have passed all the tests and the combination is
  832.      to be allowed.  */
  833.  
  834.   *pdest = dest;
  835.   *psrc = src;
  836.  
  837.   return 1;
  838. }
  839.  
  840. /* LOC is the location within I3 that contains its pattern or the component
  841.    of a PARALLEL of the pattern.  We validate that it is valid for combining.
  842.  
  843.    One problem is if I3 modifies its output, as opposed to replacing it
  844.    entirely, we can't allow the output to contain I2DEST or I1DEST as doing
  845.    so would produce an insn that is not equivalent to the original insns.
  846.  
  847.    Consider:
  848.  
  849.          (set (reg:DI 101) (reg:DI 100))
  850.      (set (subreg:SI (reg:DI 101) 0) <foo>)
  851.  
  852.    This is NOT equivalent to:
  853.  
  854.          (parallel [(set (subreg:SI (reg:DI 100) 0) <foo>)
  855.              (set (reg:DI 101) (reg:DI 100))])
  856.  
  857.    Not only does this modify 100 (in which case it might still be valid
  858.    if 100 were dead in I2), it sets 101 to the ORIGINAL value of 100. 
  859.  
  860.    We can also run into a problem if I2 sets a register that I1
  861.    uses and I1 gets directly substituted into I3 (not via I2).  In that
  862.    case, we would be getting the wrong value of I2DEST into I3, so we
  863.    must reject the combination.  This case occurs when I2 and I1 both
  864.    feed into I3, rather than when I1 feeds into I2, which feeds into I3.
  865.    If I1_NOT_IN_SRC is non-zero, it means that finding I1 in the source
  866.    of a SET must prevent combination from occurring.
  867.  
  868.    On machines where SMALL_REGISTER_CLASSES is defined, we don't combine
  869.    if the destination of a SET is a hard register.
  870.  
  871.    Before doing the above check, we first try to expand a field assignment
  872.    into a set of logical operations.
  873.  
  874.    If PI3_DEST_KILLED is non-zero, it is a pointer to a location in which
  875.    we place a register that is both set and used within I3.  If more than one
  876.    such register is detected, we fail.
  877.  
  878.    Return 1 if the combination is valid, zero otherwise.  */
  879.  
  880. static int
  881. combinable_i3pat (i3, loc, i2dest, i1dest, i1_not_in_src, pi3dest_killed)
  882.      rtx i3;
  883.      rtx *loc;
  884.      rtx i2dest;
  885.      rtx i1dest;
  886.      int i1_not_in_src;
  887.      rtx *pi3dest_killed;
  888. {
  889.   rtx x = *loc;
  890.  
  891.   if (GET_CODE (x) == SET)
  892.     {
  893.       rtx set = expand_field_assignment (x);
  894.       rtx dest = SET_DEST (set);
  895.       rtx src = SET_SRC (set);
  896.       rtx inner_dest = dest, inner_src = src;
  897.  
  898.       SUBST (*loc, set);
  899.  
  900.       while (GET_CODE (inner_dest) == STRICT_LOW_PART
  901.          || GET_CODE (inner_dest) == SUBREG
  902.          || GET_CODE (inner_dest) == ZERO_EXTRACT)
  903.     inner_dest = XEXP (inner_dest, 0);
  904.  
  905.   /* We probably don't need this any more now that LIMIT_RELOAD_CLASS
  906.      was added.  */
  907. #if 0
  908.       while (GET_CODE (inner_src) == STRICT_LOW_PART
  909.          || GET_CODE (inner_src) == SUBREG
  910.          || GET_CODE (inner_src) == ZERO_EXTRACT)
  911.     inner_src = XEXP (inner_src, 0);
  912.  
  913.       /* If it is better that two different modes keep two different pseudos,
  914.      avoid combining them.  This avoids producing the following pattern
  915.      on a 386:
  916.       (set (subreg:SI (reg/v:QI 21) 0)
  917.            (lshiftrt:SI (reg/v:SI 20)
  918.                (const_int 24)))
  919.      If that were made, reload could not handle the pair of
  920.      reg 20/21, since it would try to get any GENERAL_REGS
  921.      but some of them don't handle QImode.  */
  922.  
  923.       if (rtx_equal_p (inner_src, i2dest)
  924.       && GET_CODE (inner_dest) == REG
  925.       && ! MODES_TIEABLE_P (GET_MODE (i2dest), GET_MODE (inner_dest)))
  926.     return 0;
  927. #endif
  928.  
  929.       /* Check for the case where I3 modifies its output, as
  930.      discussed above.  */
  931.       if ((inner_dest != dest
  932.        && (reg_overlap_mentioned_p (i2dest, inner_dest)
  933.            || (i1dest && reg_overlap_mentioned_p (i1dest, inner_dest))))
  934.       /* This is the same test done in can_combine_p except that we
  935.          allow a hard register with SMALL_REGISTER_CLASSES if SRC is a
  936.          CALL operation.  */
  937.       || (GET_CODE (inner_dest) == REG
  938.           && REGNO (inner_dest) < FIRST_PSEUDO_REGISTER
  939. #ifdef SMALL_REGISTER_CLASSES
  940.           && GET_CODE (src) != CALL
  941. #else
  942.           && ! HARD_REGNO_MODE_OK (REGNO (inner_dest),
  943.                        GET_MODE (inner_dest))
  944. #endif
  945.           )
  946.  
  947.       || (i1_not_in_src && reg_overlap_mentioned_p (i1dest, src)))
  948.     return 0;
  949.  
  950.       /* If DEST is used in I3, it is being killed in this insn,
  951.      so record that for later.  */
  952.       if (pi3dest_killed && GET_CODE (dest) == REG
  953.       && reg_referenced_p (dest, PATTERN (i3)))
  954.     {
  955.       if (*pi3dest_killed)
  956.         return 0;
  957.  
  958.       *pi3dest_killed = dest;
  959.     }
  960.     }
  961.  
  962.   else if (GET_CODE (x) == PARALLEL)
  963.     {
  964.       int i;
  965.  
  966.       for (i = 0; i < XVECLEN (x, 0); i++)
  967.     if (! combinable_i3pat (i3, &XVECEXP (x, 0, i), i2dest, i1dest,
  968.                 i1_not_in_src, pi3dest_killed))
  969.       return 0;
  970.     }
  971.  
  972.   return 1;
  973. }
  974.  
  975. /* Try to combine the insns I1 and I2 into I3.
  976.    Here I1 and I2 appear earlier than I3.
  977.    I1 can be zero; then we combine just I2 into I3.
  978.  
  979.    It we are combining three insns and the resulting insn is not recognized,
  980.    try splitting it into two insns.  If that happens, I2 and I3 are retained
  981.    and I1 is pseudo-deleted by turning it into a NOTE.  Otherwise, I1 and I2
  982.    are pseudo-deleted.
  983.  
  984.    If we created two insns, return I2; otherwise return I3.
  985.    Return 0 if the combination does not work.  Then nothing is changed.  */
  986.  
  987. static rtx
  988. try_combine (i3, i2, i1)
  989.      register rtx i3, i2, i1;
  990. {
  991.   /* New patterns for I3 and I3, respectively.  */
  992.   rtx newpat, newi2pat = 0;
  993.   /* Indicates need to preserve SET in I1 or I2 in I3 if it is not dead.  */
  994.   int added_sets_1, added_sets_2;
  995.   /* Total number of SETs to put into I3.  */
  996.   int total_sets;
  997.   /* Nonzero is I2's body now appears in I3.  */
  998.   int i2_is_used;
  999.   /* INSN_CODEs for new I3, new I2, and user of condition code.  */
  1000.   int insn_code_number, i2_code_number, other_code_number;
  1001.   /* Contains I3 if the destination of I3 is used in its source, which means
  1002.      that the old life of I3 is being killed.  If that usage is placed into
  1003.      I2 and not in I3, a REG_DEAD note must be made.  */
  1004.   rtx i3dest_killed = 0;
  1005.   /* SET_DEST and SET_SRC of I2 and I1.  */
  1006.   rtx i2dest, i2src, i1dest = 0, i1src = 0;
  1007.   /* PATTERN (I2), or a copy of it in certain cases.  */
  1008.   rtx i2pat;
  1009.   /* Indicates if I2DEST or I1DEST is in I2SRC or I1_SRC.  */
  1010.   int i2dest_in_i2src, i1dest_in_i1src = 0, i2dest_in_i1src = 0;
  1011.   int i1_feeds_i3 = 0;
  1012.   /* Notes that must be added to REG_NOTES in I3 and I2.  */
  1013.   rtx new_i3_notes, new_i2_notes;
  1014.  
  1015.   int maxreg;
  1016.   rtx temp;
  1017.   register rtx link;
  1018.   int i;
  1019.  
  1020.   /* If any of I1, I2, and I3 isn't really an insn, we can't do anything.
  1021.      This can occur when flow deletes an insn that it has merged into an
  1022.      auto-increment address.  We also can't do anything if I3 has a
  1023.      REG_LIBCALL note since we don't want to disrupt the contiguity of a
  1024.      libcall.  */
  1025.  
  1026.   if (GET_RTX_CLASS (GET_CODE (i3)) != 'i'
  1027.       || GET_RTX_CLASS (GET_CODE (i2)) != 'i'
  1028.       || (i1 && GET_RTX_CLASS (GET_CODE (i1)) != 'i')
  1029.       || find_reg_note (i3, REG_LIBCALL, NULL_RTX))
  1030.     return 0;
  1031.  
  1032.   combine_attempts++;
  1033.  
  1034.   undobuf.num_undo = previous_num_undos = 0;
  1035.   undobuf.other_insn = 0;
  1036.  
  1037.   /* Save the current high-water-mark so we can free storage if we didn't
  1038.      accept this combination.  */
  1039.   undobuf.storage = (char *) oballoc (0);
  1040.  
  1041.   /* If I1 and I2 both feed I3, they can be in any order.  To simplify the
  1042.      code below, set I1 to be the earlier of the two insns.  */
  1043.   if (i1 && INSN_CUID (i1) > INSN_CUID (i2))
  1044.     temp = i1, i1 = i2, i2 = temp;
  1045.  
  1046.   /* First check for one important special-case that the code below will
  1047.      not handle.  Namely, the case where I1 is zero, I2 has multiple sets,
  1048.      and I3 is a SET whose SET_SRC is a SET_DEST in I2.  In that case,
  1049.      we may be able to replace that destination with the destination of I3.
  1050.      This occurs in the common code where we compute both a quotient and
  1051.      remainder into a structure, in which case we want to do the computation
  1052.      directly into the structure to avoid register-register copies.
  1053.  
  1054.      We make very conservative checks below and only try to handle the
  1055.      most common cases of this.  For example, we only handle the case
  1056.      where I2 and I3 are adjacent to avoid making difficult register
  1057.      usage tests.  */
  1058.  
  1059.   if (i1 == 0 && GET_CODE (i3) == INSN && GET_CODE (PATTERN (i3)) == SET
  1060.       && GET_CODE (SET_SRC (PATTERN (i3))) == REG
  1061.       && REGNO (SET_SRC (PATTERN (i3))) >= FIRST_PSEUDO_REGISTER
  1062. #ifdef SMALL_REGISTER_CLASSES
  1063.       && (GET_CODE (SET_DEST (PATTERN (i3))) != REG
  1064.       || REGNO (SET_DEST (PATTERN (i3))) >= FIRST_PSEUDO_REGISTER)
  1065. #endif
  1066.       && find_reg_note (i3, REG_DEAD, SET_SRC (PATTERN (i3)))
  1067.       && GET_CODE (PATTERN (i2)) == PARALLEL
  1068.       && ! side_effects_p (SET_DEST (PATTERN (i3)))
  1069.       /* If the dest of I3 is a ZERO_EXTRACT or STRICT_LOW_PART, the code
  1070.      below would need to check what is inside (and reg_overlap_mentioned_p
  1071.      doesn't support those codes anyway).  Don't allow those destinations;
  1072.      the resulting insn isn't likely to be recognized anyway.  */
  1073.       && GET_CODE (SET_DEST (PATTERN (i3))) != ZERO_EXTRACT
  1074.       && GET_CODE (SET_DEST (PATTERN (i3))) != STRICT_LOW_PART
  1075.       && ! reg_overlap_mentioned_p (SET_SRC (PATTERN (i3)),
  1076.                     SET_DEST (PATTERN (i3)))
  1077.       && next_real_insn (i2) == i3)
  1078.     {
  1079.       rtx p2 = PATTERN (i2);
  1080.  
  1081.       /* Make sure that the destination of I3,
  1082.      which we are going to substitute into one output of I2,
  1083.      is not used within another output of I2.  We must avoid making this:
  1084.      (parallel [(set (mem (reg 69)) ...)
  1085.             (set (reg 69) ...)])
  1086.      which is not well-defined as to order of actions.
  1087.      (Besides, reload can't handle output reloads for this.)
  1088.  
  1089.      The problem can also happen if the dest of I3 is a memory ref,
  1090.      if another dest in I2 is an indirect memory ref.  */
  1091.       for (i = 0; i < XVECLEN (p2, 0); i++)
  1092.     if (GET_CODE (XVECEXP (p2, 0, i)) == SET
  1093.         && reg_overlap_mentioned_p (SET_DEST (PATTERN (i3)),
  1094.                     SET_DEST (XVECEXP (p2, 0, i))))
  1095.       break;
  1096.  
  1097.       if (i == XVECLEN (p2, 0))
  1098.     for (i = 0; i < XVECLEN (p2, 0); i++)
  1099.       if (SET_DEST (XVECEXP (p2, 0, i)) == SET_SRC (PATTERN (i3)))
  1100.         {
  1101.           combine_merges++;
  1102.  
  1103.           subst_insn = i3;
  1104.           subst_low_cuid = INSN_CUID (i2);
  1105.  
  1106.           added_sets_2 = 0;
  1107.           i2dest = SET_SRC (PATTERN (i3));
  1108.  
  1109.           /* Replace the dest in I2 with our dest and make the resulting
  1110.          insn the new pattern for I3.  Then skip to where we
  1111.          validate the pattern.  Everything was set up above.  */
  1112.           SUBST (SET_DEST (XVECEXP (p2, 0, i)), 
  1113.              SET_DEST (PATTERN (i3)));
  1114.  
  1115.           newpat = p2;
  1116.           goto validate_replacement;
  1117.         }
  1118.     }
  1119.  
  1120. #ifndef HAVE_cc0
  1121.   /* If we have no I1 and I2 looks like:
  1122.     (parallel [(set (reg:CC X) (compare:CC OP (const_int 0)))
  1123.            (set Y OP)])
  1124.      make up a dummy I1 that is
  1125.     (set Y OP)
  1126.      and change I2 to be
  1127.         (set (reg:CC X) (compare:CC Y (const_int 0)))
  1128.  
  1129.      (We can ignore any trailing CLOBBERs.)
  1130.  
  1131.      This undoes a previous combination and allows us to match a branch-and-
  1132.      decrement insn.  */
  1133.  
  1134.   if (i1 == 0 && GET_CODE (PATTERN (i2)) == PARALLEL
  1135.       && XVECLEN (PATTERN (i2), 0) >= 2
  1136.       && GET_CODE (XVECEXP (PATTERN (i2), 0, 0)) == SET
  1137.       && (GET_MODE_CLASS (GET_MODE (SET_DEST (XVECEXP (PATTERN (i2), 0, 0))))
  1138.       == MODE_CC)
  1139.       && GET_CODE (SET_SRC (XVECEXP (PATTERN (i2), 0, 0))) == COMPARE
  1140.       && XEXP (SET_SRC (XVECEXP (PATTERN (i2), 0, 0)), 1) == const0_rtx
  1141.       && GET_CODE (XVECEXP (PATTERN (i2), 0, 1)) == SET
  1142.       && GET_CODE (SET_DEST (XVECEXP (PATTERN (i2), 0, 1))) == REG
  1143.       && rtx_equal_p (XEXP (SET_SRC (XVECEXP (PATTERN (i2), 0, 0)), 0),
  1144.               SET_SRC (XVECEXP (PATTERN (i2), 0, 1))))
  1145.     {
  1146.       for (i =  XVECLEN (PATTERN (i2), 0) - 1; i >= 2; i--)
  1147.     if (GET_CODE (XVECEXP (PATTERN (i2), 0, i)) != CLOBBER)
  1148.       break;
  1149.  
  1150.       if (i == 1)
  1151.     {
  1152.       /* We make I1 with the same INSN_UID as I2.  This gives it
  1153.          the same INSN_CUID for value tracking.  Our fake I1 will
  1154.          never appear in the insn stream so giving it the same INSN_UID
  1155.          as I2 will not cause a problem.  */
  1156.  
  1157.       i1 = gen_rtx (INSN, VOIDmode, INSN_UID (i2), 0, i2,
  1158.             XVECEXP (PATTERN (i2), 0, 1), -1, 0, 0);
  1159.  
  1160.       SUBST (PATTERN (i2), XVECEXP (PATTERN (i2), 0, 0));
  1161.       SUBST (XEXP (SET_SRC (PATTERN (i2)), 0),
  1162.          SET_DEST (PATTERN (i1)));
  1163.     }
  1164.     }
  1165. #endif
  1166.  
  1167.   /* Verify that I2 and I1 are valid for combining.  */
  1168.   if (! can_combine_p (i2, i3, i1, NULL_RTX, &i2dest, &i2src)
  1169.       || (i1 && ! can_combine_p (i1, i3, NULL_RTX, i2, &i1dest, &i1src)))
  1170.     {
  1171.       undo_all ();
  1172.       return 0;
  1173.     }
  1174.  
  1175.   /* Record whether I2DEST is used in I2SRC and similarly for the other
  1176.      cases.  Knowing this will help in register status updating below.  */
  1177.   i2dest_in_i2src = reg_overlap_mentioned_p (i2dest, i2src);
  1178.   i1dest_in_i1src = i1 && reg_overlap_mentioned_p (i1dest, i1src);
  1179.   i2dest_in_i1src = i1 && reg_overlap_mentioned_p (i2dest, i1src);
  1180.  
  1181.   /* See if I1 directly feeds into I3.  It does if I1DEST is not used
  1182.      in I2SRC.  */
  1183.   i1_feeds_i3 = i1 && ! reg_overlap_mentioned_p (i1dest, i2src);
  1184.  
  1185.   /* Ensure that I3's pattern can be the destination of combines.  */
  1186.   if (! combinable_i3pat (i3, &PATTERN (i3), i2dest, i1dest,
  1187.               i1 && i2dest_in_i1src && i1_feeds_i3,
  1188.               &i3dest_killed))
  1189.     {
  1190.       undo_all ();
  1191.       return 0;
  1192.     }
  1193.  
  1194.   /* If I3 has an inc, then give up if I1 or I2 uses the reg that is inc'd.
  1195.      We used to do this EXCEPT in one case: I3 has a post-inc in an
  1196.      output operand.  However, that exception can give rise to insns like
  1197.          mov r3,(r3)+
  1198.      which is a famous insn on the PDP-11 where the value of r3 used as the
  1199.      source was model-dependent.  Avoid this sort of thing.  */
  1200.  
  1201. #if 0
  1202.   if (!(GET_CODE (PATTERN (i3)) == SET
  1203.     && GET_CODE (SET_SRC (PATTERN (i3))) == REG
  1204.     && GET_CODE (SET_DEST (PATTERN (i3))) == MEM
  1205.     && (GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_INC
  1206.         || GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_DEC)))
  1207.     /* It's not the exception.  */
  1208. #endif
  1209. #ifdef AUTO_INC_DEC
  1210.     for (link = REG_NOTES (i3); link; link = XEXP (link, 1))
  1211.       if (REG_NOTE_KIND (link) == REG_INC
  1212.       && (reg_overlap_mentioned_p (XEXP (link, 0), PATTERN (i2))
  1213.           || (i1 != 0
  1214.           && reg_overlap_mentioned_p (XEXP (link, 0), PATTERN (i1)))))
  1215.     {
  1216.       undo_all ();
  1217.       return 0;
  1218.     }
  1219. #endif
  1220.  
  1221.   /* See if the SETs in I1 or I2 need to be kept around in the merged
  1222.      instruction: whenever the value set there is still needed past I3.
  1223.      For the SETs in I2, this is easy: we see if I2DEST dies or is set in I3.
  1224.  
  1225.      For the SET in I1, we have two cases:  If I1 and I2 independently
  1226.      feed into I3, the set in I1 needs to be kept around if I1DEST dies
  1227.      or is set in I3.  Otherwise (if I1 feeds I2 which feeds I3), the set
  1228.      in I1 needs to be kept around unless I1DEST dies or is set in either
  1229.      I2 or I3.  We can distinguish these cases by seeing if I2SRC mentions
  1230.      I1DEST.  If so, we know I1 feeds into I2.  */
  1231.  
  1232.   added_sets_2 = ! dead_or_set_p (i3, i2dest);
  1233.  
  1234. #ifdef MPW_C
  1235. {
  1236.   int t1;
  1237.   if(i1) {
  1238.     if(i1_feeds_i3) {
  1239.       t1 = dead_or_set_p (i3, i1dest);
  1240.     } else {
  1241.       t1 = dead_or_set_p (i3, i1dest) || dead_or_set_p (i2, i1dest);
  1242.     }
  1243.     added_sets_1 = !t1;
  1244.   } else {
  1245.     added_sets_1 = 0;
  1246.   }
  1247. }
  1248. #else
  1249.   added_sets_1
  1250.     = i1 && ! (i1_feeds_i3 ? dead_or_set_p (i3, i1dest)
  1251.            : (dead_or_set_p (i3, i1dest) || dead_or_set_p (i2, i1dest)));
  1252. #endif
  1253.  
  1254.   /* If the set in I2 needs to be kept around, we must make a copy of
  1255.      PATTERN (I2), so that when we substitute I1SRC for I1DEST in
  1256.      PATTERN (I2), we are only substituting for the original I1DEST, not into
  1257.      an already-substituted copy.  This also prevents making self-referential
  1258.      rtx.  If I2 is a PARALLEL, we just need the piece that assigns I2SRC to
  1259.      I2DEST.  */
  1260.  
  1261.   i2pat = (GET_CODE (PATTERN (i2)) == PARALLEL
  1262.        ? gen_rtx (SET, VOIDmode, i2dest, i2src)
  1263.        : PATTERN (i2));
  1264.  
  1265.   if (added_sets_2)
  1266.     i2pat = copy_rtx (i2pat);
  1267.  
  1268.   combine_merges++;
  1269.  
  1270.   /* Substitute in the latest insn for the regs set by the earlier ones.  */
  1271.  
  1272.   maxreg = max_reg_num ();
  1273.  
  1274.   subst_insn = i3;
  1275.  
  1276.   /* It is possible that the source of I2 or I1 may be performing an
  1277.      unneeded operation, such as a ZERO_EXTEND of something that is known
  1278.      to have the high part zero.  Handle that case by letting subst look at
  1279.      the innermost one of them.
  1280.  
  1281.      Another way to do this would be to have a function that tries to
  1282.      simplify a single insn instead of merging two or more insns.  We don't
  1283.      do this because of the potential of infinite loops and because
  1284.      of the potential extra memory required.  However, doing it the way
  1285.      we are is a bit of a kludge and doesn't catch all cases.
  1286.  
  1287.      But only do this if -fexpensive-optimizations since it slows things down
  1288.      and doesn't usually win.  */
  1289.  
  1290.   if (flag_expensive_optimizations)
  1291.     {
  1292.       /* Pass pc_rtx so no substitutions are done, just simplifications.
  1293.      The cases that we are interested in here do not involve the few
  1294.      cases were is_replaced is checked.  */
  1295.       if (i1)
  1296.     {
  1297.       subst_low_cuid = INSN_CUID (i1);
  1298.       i1src = subst (i1src, pc_rtx, pc_rtx, 0, 0);
  1299.     }
  1300.       else
  1301.     {
  1302.       subst_low_cuid = INSN_CUID (i2);
  1303.       i2src = subst (i2src, pc_rtx, pc_rtx, 0, 0);
  1304.     }
  1305.  
  1306.       previous_num_undos = undobuf.num_undo;
  1307.     }
  1308.  
  1309. #ifndef HAVE_cc0
  1310.   /* Many machines that don't use CC0 have insns that can both perform an
  1311.      arithmetic operation and set the condition code.  These operations will
  1312.      be represented as a PARALLEL with the first element of the vector
  1313.      being a COMPARE of an arithmetic operation with the constant zero.
  1314.      The second element of the vector will set some pseudo to the result
  1315.      of the same arithmetic operation.  If we simplify the COMPARE, we won't
  1316.      match such a pattern and so will generate an extra insn.   Here we test
  1317.      for this case, where both the comparison and the operation result are
  1318.      needed, and make the PARALLEL by just replacing I2DEST in I3SRC with
  1319.      I2SRC.  Later we will make the PARALLEL that contains I2.  */
  1320.  
  1321.   if (i1 == 0 && added_sets_2 && GET_CODE (PATTERN (i3)) == SET
  1322.       && GET_CODE (SET_SRC (PATTERN (i3))) == COMPARE
  1323.       && XEXP (SET_SRC (PATTERN (i3)), 1) == const0_rtx
  1324.       && rtx_equal_p (XEXP (SET_SRC (PATTERN (i3)), 0), i2dest))
  1325.     {
  1326.       rtx *cc_use;
  1327.       enum machine_mode compare_mode;
  1328.  
  1329.       newpat = PATTERN (i3);
  1330.       SUBST (XEXP (SET_SRC (newpat), 0), i2src);
  1331.  
  1332.       i2_is_used = 1;
  1333.  
  1334. #ifdef EXTRA_CC_MODES
  1335.       /* See if a COMPARE with the operand we substituted in should be done
  1336.      with the mode that is currently being used.  If not, do the same
  1337.      processing we do in `subst' for a SET; namely, if the destination
  1338.      is used only once, try to replace it with a register of the proper
  1339.      mode and also replace the COMPARE.  */
  1340.       if (undobuf.other_insn == 0
  1341.       && (cc_use = find_single_use (SET_DEST (newpat), i3,
  1342.                     &undobuf.other_insn))
  1343.       && ((compare_mode = SELECT_CC_MODE (GET_CODE (*cc_use),
  1344.                           i2src, const0_rtx))
  1345.           != GET_MODE (SET_DEST (newpat))))
  1346.     {
  1347.       int regno = REGNO (SET_DEST (newpat));
  1348.       rtx new_dest = gen_rtx (REG, compare_mode, regno);
  1349.  
  1350.       if (regno < FIRST_PSEUDO_REGISTER
  1351.           || (reg_n_sets[regno] == 1 && ! added_sets_2
  1352.           && ! REG_USERVAR_P (SET_DEST (newpat))))
  1353.         {
  1354.           if (regno >= FIRST_PSEUDO_REGISTER)
  1355.         SUBST (regno_reg_rtx[regno], new_dest);
  1356.  
  1357.           SUBST (SET_DEST (newpat), new_dest);
  1358.           SUBST (XEXP (*cc_use, 0), new_dest);
  1359.           SUBST (SET_SRC (newpat),
  1360.              gen_rtx_combine (COMPARE, compare_mode,
  1361.                       i2src, const0_rtx));
  1362.         }
  1363.       else
  1364.         undobuf.other_insn = 0;
  1365.     }
  1366. #endif      
  1367.     }
  1368.   else
  1369. #endif
  1370.     {
  1371.       n_occurrences = 0;        /* `subst' counts here */
  1372.  
  1373.       /* If I1 feeds into I2 (not into I3) and I1DEST is in I1SRC, we
  1374.      need to make a unique copy of I2SRC each time we substitute it
  1375.      to avoid self-referential rtl.  */
  1376.  
  1377.       subst_low_cuid = INSN_CUID (i2);
  1378.       newpat = subst (PATTERN (i3), i2dest, i2src, 0,
  1379.               ! i1_feeds_i3 && i1dest_in_i1src);
  1380.       previous_num_undos = undobuf.num_undo;
  1381.  
  1382.       /* Record whether i2's body now appears within i3's body.  */
  1383.       i2_is_used = n_occurrences;
  1384.     }
  1385.  
  1386.   /* If we already got a failure, don't try to do more.  Otherwise,
  1387.      try to substitute in I1 if we have it.  */
  1388.  
  1389.   if (i1 && GET_CODE (newpat) != CLOBBER)
  1390.     {
  1391.       /* Before we can do this substitution, we must redo the test done
  1392.      above (see detailed comments there) that ensures  that I1DEST
  1393.      isn't mentioned in any SETs in NEWPAT that are field assignments. */
  1394.  
  1395.       if (! combinable_i3pat (NULL_RTX, &newpat, i1dest, NULL_RTX,
  1396.                   0, NULL_PTR))
  1397.     {
  1398.       undo_all ();
  1399.       return 0;
  1400.     }
  1401.  
  1402.       n_occurrences = 0;
  1403.       subst_low_cuid = INSN_CUID (i1);
  1404.       newpat = subst (newpat, i1dest, i1src, 0, 0);
  1405.       previous_num_undos = undobuf.num_undo;
  1406.     }
  1407.  
  1408.   /* Fail if an autoincrement side-effect has been duplicated.  Be careful
  1409.      to count all the ways that I2SRC and I1SRC can be used.  */
  1410.   if ((FIND_REG_INC_NOTE (i2, NULL_RTX) != 0
  1411.        && i2_is_used + added_sets_2 > 1)
  1412.       || (i1 != 0 && FIND_REG_INC_NOTE (i1, NULL_RTX) != 0
  1413.       && (n_occurrences + added_sets_1 + (added_sets_2 && ! i1_feeds_i3)
  1414.           > 1))
  1415.       /* Fail if we tried to make a new register (we used to abort, but there's
  1416.      really no reason to).  */
  1417.       || max_reg_num () != maxreg
  1418.       /* Fail if we couldn't do something and have a CLOBBER.  */
  1419.       || GET_CODE (newpat) == CLOBBER)
  1420.     {
  1421.       undo_all ();
  1422.       return 0;
  1423.     }
  1424.  
  1425.   /* If the actions of the earlier insns must be kept
  1426.      in addition to substituting them into the latest one,
  1427.      we must make a new PARALLEL for the latest insn
  1428.      to hold additional the SETs.  */
  1429.  
  1430.   if (added_sets_1 || added_sets_2)
  1431.     {
  1432.       combine_extras++;
  1433.  
  1434.       if (GET_CODE (newpat) == PARALLEL)
  1435.     {
  1436.       rtvec old = XVEC (newpat, 0);
  1437.       total_sets = XVECLEN (newpat, 0) + added_sets_1 + added_sets_2;
  1438.       newpat = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (total_sets));
  1439.       bcopy (&old->elem[0], &XVECEXP (newpat, 0, 0),
  1440.          sizeof (old->elem[0]) * old->num_elem);
  1441.     }
  1442.       else
  1443.     {
  1444.       rtx old = newpat;
  1445.       total_sets = 1 + added_sets_1 + added_sets_2;
  1446.       newpat = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (total_sets));
  1447.       XVECEXP (newpat, 0, 0) = old;
  1448.     }
  1449.  
  1450.      if (added_sets_1)
  1451.        XVECEXP (newpat, 0, --total_sets)
  1452.      = (GET_CODE (PATTERN (i1)) == PARALLEL
  1453.         ? gen_rtx (SET, VOIDmode, i1dest, i1src) : PATTERN (i1));
  1454.  
  1455.      if (added_sets_2)
  1456.     {
  1457.       /* If there is no I1, use I2's body as is.  We used to also not do
  1458.          the subst call below if I2 was substituted into I3,
  1459.          but that could lose a simplification.  */
  1460.       if (i1 == 0)
  1461.         XVECEXP (newpat, 0, --total_sets) = i2pat;
  1462.       else
  1463.         /* See comment where i2pat is assigned.  */
  1464.         XVECEXP (newpat, 0, --total_sets)
  1465.           = subst (i2pat, i1dest, i1src, 0, 0);
  1466.     }
  1467.     }
  1468.  
  1469.   /* We come here when we are replacing a destination in I2 with the
  1470.      destination of I3.  */
  1471.  validate_replacement:
  1472.  
  1473.   /* Is the result of combination a valid instruction?  */
  1474.   insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1475.  
  1476.   /* If the result isn't valid, see if it is a PARALLEL of two SETs where
  1477.      the second SET's destination is a register that is unused.  In that case,
  1478.      we just need the first SET.   This can occur when simplifying a divmod
  1479.      insn.  We *must* test for this case here because the code below that
  1480.      splits two independent SETs doesn't handle this case correctly when it
  1481.      updates the register status.  Also check the case where the first
  1482.      SET's destination is unused.  That would not cause incorrect code, but
  1483.      does cause an unneeded insn to remain.  */
  1484.  
  1485.   if (insn_code_number < 0 && GET_CODE (newpat) == PARALLEL
  1486.       && XVECLEN (newpat, 0) == 2
  1487.       && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
  1488.       && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
  1489.       && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) == REG
  1490.       && find_reg_note (i3, REG_UNUSED, SET_DEST (XVECEXP (newpat, 0, 1)))
  1491.       && ! side_effects_p (SET_SRC (XVECEXP (newpat, 0, 1)))
  1492.       && asm_noperands (newpat) < 0)
  1493.     {
  1494.       newpat = XVECEXP (newpat, 0, 0);
  1495.       insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1496.     }
  1497.  
  1498.   else if (insn_code_number < 0 && GET_CODE (newpat) == PARALLEL
  1499.        && XVECLEN (newpat, 0) == 2
  1500.        && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
  1501.        && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
  1502.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) == REG
  1503.        && find_reg_note (i3, REG_UNUSED, SET_DEST (XVECEXP (newpat, 0, 0)))
  1504.        && ! side_effects_p (SET_SRC (XVECEXP (newpat, 0, 0)))
  1505.        && asm_noperands (newpat) < 0)
  1506.     {
  1507.       newpat = XVECEXP (newpat, 0, 1);
  1508.       insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1509.     }
  1510.  
  1511.   /* See if this is an XOR.  If so, perhaps the problem is that the
  1512.      constant is out of range.  Replace it with a complemented XOR with
  1513.      a complemented constant; it might be in range.  */
  1514.  
  1515.   else if (insn_code_number < 0 && GET_CODE (newpat) == SET
  1516.        && GET_CODE (SET_SRC (newpat)) == XOR
  1517.        && GET_CODE (XEXP (SET_SRC (newpat), 1)) == CONST_INT
  1518.        && ((temp = simplify_unary_operation (NOT,
  1519.                          GET_MODE (SET_SRC (newpat)),
  1520.                          XEXP (SET_SRC (newpat), 1),
  1521.                          GET_MODE (SET_SRC (newpat))))
  1522.            != 0))
  1523.     {
  1524.       enum machine_mode i_mode = GET_MODE (SET_SRC (newpat));
  1525.       rtx pat
  1526.     = gen_rtx_combine (SET, VOIDmode, SET_DEST (newpat),
  1527.                gen_unary (NOT, i_mode,
  1528.                       gen_binary (XOR, i_mode,
  1529.                           XEXP (SET_SRC (newpat), 0),
  1530.                           temp)));
  1531.  
  1532.       insn_code_number = recog_for_combine (&pat, i3, &new_i3_notes);
  1533.       if (insn_code_number >= 0)
  1534.     newpat = pat;
  1535.     }
  1536.                             
  1537.   /* If we were combining three insns and the result is a simple SET
  1538.      with no ASM_OPERANDS that wasn't recognized, try to split it into two
  1539.      insns.  There are two ways to do this.  It can be split using a 
  1540.      machine-specific method (like when you have an addition of a large
  1541.      constant) or by combine in the function find_split_point.  */
  1542.  
  1543.   if (i1 && insn_code_number < 0 && GET_CODE (newpat) == SET
  1544.       && asm_noperands (newpat) < 0)
  1545.     {
  1546.       rtx m_split, *split;
  1547.       rtx ni2dest = i2dest;
  1548.  
  1549.       /* See if the MD file can split NEWPAT.  If it can't, see if letting it
  1550.      use I2DEST as a scratch register will help.  In the latter case,
  1551.      convert I2DEST to the mode of the source of NEWPAT if we can.  */
  1552.  
  1553.       m_split = split_insns (newpat, i3);
  1554.  
  1555.       /* We can only use I2DEST as a scratch reg if it doesn't overlap any
  1556.      inputs of NEWPAT.  */
  1557.  
  1558.       /* ??? If I2DEST is not safe, and I1DEST exists, then it would be
  1559.      possible to try that as a scratch reg.  This would require adding
  1560.      more code to make it work though.  */
  1561.  
  1562.       if (m_split == 0 && ! reg_overlap_mentioned_p (ni2dest, newpat))
  1563.     {
  1564.       /* If I2DEST is a hard register or the only use of a pseudo,
  1565.          we can change its mode.  */
  1566.       if (GET_MODE (SET_DEST (newpat)) != GET_MODE (i2dest)
  1567.           && GET_MODE (SET_DEST (newpat)) != VOIDmode
  1568.           && GET_CODE (i2dest) == REG
  1569.           && (REGNO (i2dest) < FIRST_PSEUDO_REGISTER
  1570.           || (reg_n_sets[REGNO (i2dest)] == 1 && ! added_sets_2
  1571.               && ! REG_USERVAR_P (i2dest))))
  1572.         ni2dest = gen_rtx (REG, GET_MODE (SET_DEST (newpat)),
  1573.                    REGNO (i2dest));
  1574.  
  1575.       m_split = split_insns (gen_rtx (PARALLEL, VOIDmode,
  1576.                       gen_rtvec (2, newpat,
  1577.                              gen_rtx (CLOBBER,
  1578.                                   VOIDmode,
  1579.                                   ni2dest))),
  1580.                  i3);
  1581.     }
  1582.  
  1583.       if (m_split && GET_CODE (m_split) == SEQUENCE
  1584.       && XVECLEN (m_split, 0) == 2
  1585.       && (next_real_insn (i2) == i3
  1586.           || ! use_crosses_set_p (PATTERN (XVECEXP (m_split, 0, 0)),
  1587.                       INSN_CUID (i2))))
  1588.     {
  1589.       rtx i2set, i3set;
  1590.       rtx newi3pat = PATTERN (XVECEXP (m_split, 0, 1));
  1591.       newi2pat = PATTERN (XVECEXP (m_split, 0, 0));
  1592.  
  1593.       i3set = single_set (XVECEXP (m_split, 0, 1));
  1594.       i2set = single_set (XVECEXP (m_split, 0, 0));
  1595.  
  1596.       /* In case we changed the mode of I2DEST, replace it in the
  1597.          pseudo-register table here.  We can't do it above in case this
  1598.          code doesn't get executed and we do a split the other way.  */
  1599.  
  1600.       if (REGNO (i2dest) >= FIRST_PSEUDO_REGISTER)
  1601.         SUBST (regno_reg_rtx[REGNO (i2dest)], ni2dest);
  1602.  
  1603.       i2_code_number = recog_for_combine (&newi2pat, i2, &new_i2_notes);
  1604.  
  1605.       /* If I2 or I3 has multiple SETs, we won't know how to track
  1606.          register status, so don't use these insns.  */
  1607.  
  1608.       if (i2_code_number >= 0 && i2set && i3set)
  1609.         insn_code_number = recog_for_combine (&newi3pat, i3,
  1610.                           &new_i3_notes);
  1611.  
  1612.       if (insn_code_number >= 0)
  1613.         newpat = newi3pat;
  1614.  
  1615.       /* It is possible that both insns now set the destination of I3.
  1616.          If so, we must show an extra use of it.  */
  1617.  
  1618.       if (insn_code_number >= 0 && GET_CODE (SET_DEST (i3set)) == REG
  1619.           && GET_CODE (SET_DEST (i2set)) == REG
  1620.           && REGNO (SET_DEST (i3set)) == REGNO (SET_DEST (i2set)))
  1621.         reg_n_sets[REGNO (SET_DEST (i2set))]++;
  1622.     }
  1623.  
  1624.       /* If we can split it and use I2DEST, go ahead and see if that
  1625.      helps things be recognized.  Verify that none of the registers
  1626.      are set between I2 and I3.  */
  1627.       if (insn_code_number < 0 && (split = find_split_point (&newpat, i3)) != 0
  1628. #ifdef HAVE_cc0
  1629.       && GET_CODE (i2dest) == REG
  1630. #endif
  1631.       /* We need I2DEST in the proper mode.  If it is a hard register
  1632.          or the only use of a pseudo, we can change its mode.  */
  1633.       && (GET_MODE (*split) == GET_MODE (i2dest)
  1634.           || GET_MODE (*split) == VOIDmode
  1635.           || REGNO (i2dest) < FIRST_PSEUDO_REGISTER
  1636.           || (reg_n_sets[REGNO (i2dest)] == 1 && ! added_sets_2
  1637.           && ! REG_USERVAR_P (i2dest)))
  1638.       && (next_real_insn (i2) == i3
  1639.           || ! use_crosses_set_p (*split, INSN_CUID (i2)))
  1640.       /* We can't overwrite I2DEST if its value is still used by
  1641.          NEWPAT.  */
  1642.       && ! reg_referenced_p (i2dest, newpat))
  1643.     {
  1644.       rtx newdest = i2dest;
  1645.  
  1646.       /* Get NEWDEST as a register in the proper mode.  We have already
  1647.          validated that we can do this.  */
  1648.       if (GET_MODE (i2dest) != GET_MODE (*split)
  1649.           && GET_MODE (*split) != VOIDmode)
  1650.         {
  1651.           newdest = gen_rtx (REG, GET_MODE (*split), REGNO (i2dest));
  1652.  
  1653.           if (REGNO (i2dest) >= FIRST_PSEUDO_REGISTER)
  1654.         SUBST (regno_reg_rtx[REGNO (i2dest)], newdest);
  1655.         }
  1656.  
  1657.       /* If *SPLIT is a (mult FOO (const_int pow2)), convert it to
  1658.          an ASHIFT.  This can occur if it was inside a PLUS and hence
  1659.          appeared to be a memory address.  This is a kludge.  */
  1660.       if (GET_CODE (*split) == MULT
  1661.           && GET_CODE (XEXP (*split, 1)) == CONST_INT
  1662.           && (i = exact_log2 (INTVAL (XEXP (*split, 1)))) >= 0)
  1663.         SUBST (*split, gen_rtx_combine (ASHIFT, GET_MODE (*split),
  1664.                         XEXP (*split, 0), GEN_INT (i)));
  1665.  
  1666. #ifdef INSN_SCHEDULING
  1667.       /* If *SPLIT is a paradoxical SUBREG, when we split it, it should
  1668.          be written as a ZERO_EXTEND.  */
  1669.       if (GET_CODE (*split) == SUBREG
  1670.           && GET_CODE (SUBREG_REG (*split)) == MEM)
  1671.         SUBST (*split, gen_rtx_combine (ZERO_EXTEND, GET_MODE (*split),
  1672.                         XEXP (*split, 0)));
  1673. #endif
  1674.  
  1675.       newi2pat = gen_rtx_combine (SET, VOIDmode, newdest, *split);
  1676.       SUBST (*split, newdest);
  1677.       i2_code_number = recog_for_combine (&newi2pat, i2, &new_i2_notes);
  1678.       if (i2_code_number >= 0)
  1679.         insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1680.     }
  1681.     }
  1682.  
  1683.   /* Check for a case where we loaded from memory in a narrow mode and
  1684.      then sign extended it, but we need both registers.  In that case,
  1685.      we have a PARALLEL with both loads from the same memory location.
  1686.      We can split this into a load from memory followed by a register-register
  1687.      copy.  This saves at least one insn, more if register allocation can
  1688.      eliminate the copy.  */
  1689.  
  1690.   else if (i1 && insn_code_number < 0 && asm_noperands (newpat) < 0
  1691.        && GET_CODE (newpat) == PARALLEL
  1692.        && XVECLEN (newpat, 0) == 2
  1693.        && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
  1694.        && GET_CODE (SET_SRC (XVECEXP (newpat, 0, 0))) == SIGN_EXTEND
  1695.        && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
  1696.        && rtx_equal_p (SET_SRC (XVECEXP (newpat, 0, 1)),
  1697.                XEXP (SET_SRC (XVECEXP (newpat, 0, 0)), 0))
  1698.        && ! use_crosses_set_p (SET_SRC (XVECEXP (newpat, 0, 1)),
  1699.                    INSN_CUID (i2))
  1700.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != ZERO_EXTRACT
  1701.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != STRICT_LOW_PART
  1702.        && ! reg_overlap_mentioned_p (SET_DEST (XVECEXP (newpat, 0, 1)),
  1703.                      SET_SRC (XVECEXP (newpat, 0, 1)))
  1704.        && ! find_reg_note (i3, REG_UNUSED,
  1705.                    SET_DEST (XVECEXP (newpat, 0, 0))))
  1706.     {
  1707.       rtx ni2dest;
  1708.  
  1709.       newi2pat = XVECEXP (newpat, 0, 0);
  1710.       ni2dest = SET_DEST (XVECEXP (newpat, 0, 0));
  1711.       newpat = XVECEXP (newpat, 0, 1);
  1712.       SUBST (SET_SRC (newpat),
  1713.          gen_lowpart_for_combine (GET_MODE (SET_SRC (newpat)), ni2dest));
  1714.       i2_code_number = recog_for_combine (&newi2pat, i2, &new_i2_notes);
  1715.       if (i2_code_number >= 0)
  1716.     insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1717.  
  1718.       if (insn_code_number >= 0)
  1719.     {
  1720.       rtx insn;
  1721.       rtx link;
  1722.  
  1723.       /* If we will be able to accept this, we have made a change to the
  1724.          destination of I3.  This can invalidate a LOG_LINKS pointing
  1725.          to I3.  No other part of combine.c makes such a transformation.
  1726.  
  1727.          The new I3 will have a destination that was previously the
  1728.          destination of I1 or I2 and which was used in i2 or I3.  Call
  1729.          distribute_links to make a LOG_LINK from the next use of
  1730.          that destination.  */
  1731.  
  1732.       PATTERN (i3) = newpat;
  1733.       distribute_links (gen_rtx (INSN_LIST, VOIDmode, i3, NULL_RTX));
  1734.  
  1735.       /* I3 now uses what used to be its destination and which is
  1736.          now I2's destination.  That means we need a LOG_LINK from
  1737.          I3 to I2.  But we used to have one, so we still will.
  1738.  
  1739.          However, some later insn might be using I2's dest and have
  1740.          a LOG_LINK pointing at I3.  We must remove this link.
  1741.          The simplest way to remove the link is to point it at I1,
  1742.          which we know will be a NOTE.  */
  1743.  
  1744.       for (insn = NEXT_INSN (i3);
  1745.            insn && GET_CODE (insn) != CODE_LABEL
  1746.            && GET_CODE (PREV_INSN (insn)) != JUMP_INSN;
  1747.            insn = NEXT_INSN (insn))
  1748.         {
  1749.           if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  1750.           && reg_referenced_p (ni2dest, PATTERN (insn)))
  1751.         {
  1752.           for (link = LOG_LINKS (insn); link;
  1753.                link = XEXP (link, 1))
  1754.             if (XEXP (link, 0) == i3)
  1755.               XEXP (link, 0) = i1;
  1756.  
  1757.           break;
  1758.         }
  1759.         }
  1760.     }
  1761.     }
  1762.         
  1763.   /* Similarly, check for a case where we have a PARALLEL of two independent
  1764.      SETs but we started with three insns.  In this case, we can do the sets
  1765.      as two separate insns.  This case occurs when some SET allows two
  1766.      other insns to combine, but the destination of that SET is still live.  */
  1767.  
  1768.   else if (i1 && insn_code_number < 0 && asm_noperands (newpat) < 0
  1769.        && GET_CODE (newpat) == PARALLEL
  1770.        && XVECLEN (newpat, 0) == 2
  1771.        && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
  1772.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) != ZERO_EXTRACT
  1773.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) != STRICT_LOW_PART
  1774.        && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
  1775.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != ZERO_EXTRACT
  1776.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != STRICT_LOW_PART
  1777.        && ! use_crosses_set_p (SET_SRC (XVECEXP (newpat, 0, 1)),
  1778.                    INSN_CUID (i2))
  1779.        /* Don't pass sets with (USE (MEM ...)) dests to the following.  */
  1780.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != USE
  1781.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) != USE
  1782.        && ! reg_referenced_p (SET_DEST (XVECEXP (newpat, 0, 1)),
  1783.                   XVECEXP (newpat, 0, 0))
  1784.        && ! reg_referenced_p (SET_DEST (XVECEXP (newpat, 0, 0)),
  1785.                   XVECEXP (newpat, 0, 1)))
  1786.     {
  1787.       newi2pat = XVECEXP (newpat, 0, 1);
  1788.       newpat = XVECEXP (newpat, 0, 0);
  1789.  
  1790.       i2_code_number = recog_for_combine (&newi2pat, i2, &new_i2_notes);
  1791.       if (i2_code_number >= 0)
  1792.     insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1793.     }
  1794.  
  1795.   /* If it still isn't recognized, fail and change things back the way they
  1796.      were.  */
  1797.   if ((insn_code_number < 0
  1798.        /* Is the result a reasonable ASM_OPERANDS?  */
  1799.        && (! check_asm_operands (newpat) || added_sets_1 || added_sets_2)))
  1800.     {
  1801.       undo_all ();
  1802.       return 0;
  1803.     }
  1804.  
  1805.   /* If we had to change another insn, make sure it is valid also.  */
  1806.   if (undobuf.other_insn)
  1807.     {
  1808.       rtx other_notes = REG_NOTES (undobuf.other_insn);
  1809.       rtx other_pat = PATTERN (undobuf.other_insn);
  1810.       rtx new_other_notes;
  1811.       rtx note, next;
  1812.  
  1813.       other_code_number = recog_for_combine (&other_pat, undobuf.other_insn,
  1814.                          &new_other_notes);
  1815.  
  1816.       if (other_code_number < 0 && ! check_asm_operands (other_pat))
  1817.     {
  1818.       undo_all ();
  1819.       return 0;
  1820.     }
  1821.  
  1822.       PATTERN (undobuf.other_insn) = other_pat;
  1823.  
  1824.       /* If any of the notes in OTHER_INSN were REG_UNUSED, ensure that they
  1825.      are still valid.  Then add any non-duplicate notes added by
  1826.      recog_for_combine.  */
  1827.       for (note = REG_NOTES (undobuf.other_insn); note; note = next)
  1828.     {
  1829.       next = XEXP (note, 1);
  1830.  
  1831.       if (REG_NOTE_KIND (note) == REG_UNUSED
  1832.           && ! reg_set_p (XEXP (note, 0), PATTERN (undobuf.other_insn)))
  1833.         {
  1834.           if (GET_CODE (XEXP (note, 0)) == REG)
  1835.         reg_n_deaths[REGNO (XEXP (note, 0))]--;
  1836.  
  1837.           remove_note (undobuf.other_insn, note);
  1838.         }
  1839.     }
  1840.  
  1841.       for (note = new_other_notes; note; note = XEXP (note, 1))
  1842.     if (GET_CODE (XEXP (note, 0)) == REG)
  1843.       reg_n_deaths[REGNO (XEXP (note, 0))]++;
  1844.  
  1845.       distribute_notes (new_other_notes, undobuf.other_insn,
  1846.             undobuf.other_insn, NULL_RTX, NULL_RTX, NULL_RTX);
  1847.     }
  1848.  
  1849.   /* We now know that we can do this combination.  Merge the insns and 
  1850.      update the status of registers and LOG_LINKS.  */
  1851.  
  1852.   {
  1853.     rtx i3notes, i2notes, i1notes = 0;
  1854.     rtx i3links, i2links, i1links = 0;
  1855.     rtx midnotes = 0;
  1856.     int all_adjacent = (next_real_insn (i2) == i3
  1857.             && (i1 == 0 || next_real_insn (i1) == i2));
  1858.     register int regno;
  1859.     /* Compute which registers we expect to eliminate.  */
  1860.     rtx elim_i2 = (newi2pat || i2dest_in_i2src || i2dest_in_i1src
  1861.            ? 0 : i2dest);
  1862.     rtx elim_i1 = i1 == 0 || i1dest_in_i1src ? 0 : i1dest;
  1863.  
  1864.     /* Get the old REG_NOTES and LOG_LINKS from all our insns and
  1865.        clear them.  */
  1866.     i3notes = REG_NOTES (i3), i3links = LOG_LINKS (i3);
  1867.     i2notes = REG_NOTES (i2), i2links = LOG_LINKS (i2);
  1868.     if (i1)
  1869.       i1notes = REG_NOTES (i1), i1links = LOG_LINKS (i1);
  1870.  
  1871.     /* Ensure that we do not have something that should not be shared but
  1872.        occurs multiple times in the new insns.  Check this by first
  1873.        resetting all the `used' flags and then copying anything is shared.  */
  1874.  
  1875.     reset_used_flags (i3notes);
  1876.     reset_used_flags (i2notes);
  1877.     reset_used_flags (i1notes);
  1878.     reset_used_flags (newpat);
  1879.     reset_used_flags (newi2pat);
  1880.     if (undobuf.other_insn)
  1881.       reset_used_flags (PATTERN (undobuf.other_insn));
  1882.  
  1883.     i3notes = copy_rtx_if_shared (i3notes);
  1884.     i2notes = copy_rtx_if_shared (i2notes);
  1885.     i1notes = copy_rtx_if_shared (i1notes);
  1886.     newpat = copy_rtx_if_shared (newpat);
  1887.     newi2pat = copy_rtx_if_shared (newi2pat);
  1888.     if (undobuf.other_insn)
  1889.       reset_used_flags (PATTERN (undobuf.other_insn));
  1890.  
  1891.     INSN_CODE (i3) = insn_code_number;
  1892.     PATTERN (i3) = newpat;
  1893.     if (undobuf.other_insn)
  1894.       INSN_CODE (undobuf.other_insn) = other_code_number;
  1895.  
  1896.     /* We had one special case above where I2 had more than one set and
  1897.        we replaced a destination of one of those sets with the destination
  1898.        of I3.  In that case, we have to update LOG_LINKS of insns later
  1899.        in this basic block.  Note that this (expensive) case is rare.  */
  1900.  
  1901.     if (GET_CODE (PATTERN (i2)) == PARALLEL)
  1902.       for (i = 0; i < XVECLEN (PATTERN (i2), 0); i++)
  1903.     if (GET_CODE (SET_DEST (XVECEXP (PATTERN (i2), 0, i))) == REG
  1904.         && SET_DEST (XVECEXP (PATTERN (i2), 0, i)) != i2dest
  1905.         && ! find_reg_note (i2, REG_UNUSED,
  1906.                 SET_DEST (XVECEXP (PATTERN (i2), 0, i))))
  1907.       {
  1908.         register rtx insn;
  1909.  
  1910.         for (insn = NEXT_INSN (i2); insn; insn = NEXT_INSN (insn))
  1911.           {
  1912.         if (insn != i3 && GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  1913.           for (link = LOG_LINKS (insn); link; link = XEXP (link, 1))
  1914.             if (XEXP (link, 0) == i2)
  1915.               XEXP (link, 0) = i3;
  1916.  
  1917.         if (GET_CODE (insn) == CODE_LABEL
  1918.             || GET_CODE (insn) == JUMP_INSN)
  1919.           break;
  1920.           }
  1921.       }
  1922.  
  1923.     LOG_LINKS (i3) = 0;
  1924.     REG_NOTES (i3) = 0;
  1925.     LOG_LINKS (i2) = 0;
  1926.     REG_NOTES (i2) = 0;
  1927.  
  1928.     if (newi2pat)
  1929.       {
  1930.     INSN_CODE (i2) = i2_code_number;
  1931.     PATTERN (i2) = newi2pat;
  1932.       }
  1933.     else
  1934.       {
  1935.     PUT_CODE (i2, NOTE);
  1936.     NOTE_LINE_NUMBER (i2) = NOTE_INSN_DELETED;
  1937.     NOTE_SOURCE_FILE (i2) = 0;
  1938.       }
  1939.  
  1940.     if (i1)
  1941.       {
  1942.     LOG_LINKS (i1) = 0;
  1943.     REG_NOTES (i1) = 0;
  1944.     PUT_CODE (i1, NOTE);
  1945.     NOTE_LINE_NUMBER (i1) = NOTE_INSN_DELETED;
  1946.     NOTE_SOURCE_FILE (i1) = 0;
  1947.       }
  1948.  
  1949.     /* Get death notes for everything that is now used in either I3 or
  1950.        I2 and used to die in a previous insn.  */
  1951.  
  1952.     move_deaths (newpat, i1 ? INSN_CUID (i1) : INSN_CUID (i2), i3, &midnotes);
  1953.     if (newi2pat)
  1954.       move_deaths (newi2pat, INSN_CUID (i1), i2, &midnotes);
  1955.  
  1956.     /* Distribute all the LOG_LINKS and REG_NOTES from I1, I2, and I3.  */
  1957.     if (i3notes)
  1958.       distribute_notes (i3notes, i3, i3, newi2pat ? i2 : NULL_RTX,
  1959.             elim_i2, elim_i1);
  1960.     if (i2notes)
  1961.       distribute_notes (i2notes, i2, i3, newi2pat ? i2 : NULL_RTX,
  1962.             elim_i2, elim_i1);
  1963.     if (i1notes)
  1964.       distribute_notes (i1notes, i1, i3, newi2pat ? i2 : NULL_RTX,
  1965.             elim_i2, elim_i1);
  1966.     if (midnotes)
  1967.       distribute_notes (midnotes, NULL_RTX, i3, newi2pat ? i2 : NULL_RTX,
  1968.             elim_i2, elim_i1);
  1969.  
  1970.     /* Distribute any notes added to I2 or I3 by recog_for_combine.  We
  1971.        know these are REG_UNUSED and want them to go to the desired insn,
  1972.        so we always pass it as i3.  We have not counted the notes in 
  1973.        reg_n_deaths yet, so we need to do so now.  */
  1974.  
  1975.     if (newi2pat && new_i2_notes)
  1976.       {
  1977.     for (temp = new_i2_notes; temp; temp = XEXP (temp, 1))
  1978.       if (GET_CODE (XEXP (temp, 0)) == REG)
  1979.         reg_n_deaths[REGNO (XEXP (temp, 0))]++;
  1980.     
  1981.     distribute_notes (new_i2_notes, i2, i2, NULL_RTX, NULL_RTX, NULL_RTX);
  1982.       }
  1983.  
  1984.     if (new_i3_notes)
  1985.       {
  1986.     for (temp = new_i3_notes; temp; temp = XEXP (temp, 1))
  1987.       if (GET_CODE (XEXP (temp, 0)) == REG)
  1988.         reg_n_deaths[REGNO (XEXP (temp, 0))]++;
  1989.     
  1990.     distribute_notes (new_i3_notes, i3, i3, NULL_RTX, NULL_RTX, NULL_RTX);
  1991.       }
  1992.  
  1993.     /* If I3DEST was used in I3SRC, it really died in I3.  We may need to
  1994.        put a REG_DEAD note for it somewhere.  Similarly for I2 and I1.
  1995.        Show an additional death due to the REG_DEAD note we make here.  If
  1996.        we discard it in distribute_notes, we will decrement it again.  */
  1997.  
  1998.     if (i3dest_killed)
  1999.       {
  2000.     if (GET_CODE (i3dest_killed) == REG)
  2001.       reg_n_deaths[REGNO (i3dest_killed)]++;
  2002.  
  2003.     distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i3dest_killed,
  2004.                    NULL_RTX),
  2005.               NULL_RTX, i3, newi2pat ? i2 : NULL_RTX,
  2006.               NULL_RTX, NULL_RTX);
  2007.       }
  2008.  
  2009.     /* For I2 and I1, we have to be careful.  If NEWI2PAT exists and sets
  2010.        I2DEST or I1DEST, the death must be somewhere before I2, not I3.  If
  2011.        we passed I3 in that case, it might delete I2.  */
  2012.  
  2013.     if (i2dest_in_i2src)
  2014.       {
  2015.     if (GET_CODE (i2dest) == REG)
  2016.       reg_n_deaths[REGNO (i2dest)]++;
  2017.  
  2018.     if (newi2pat && reg_set_p (i2dest, newi2pat))
  2019.       distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i2dest, NULL_RTX),
  2020.                 NULL_RTX, i2, NULL_RTX, NULL_RTX, NULL_RTX);
  2021.     else
  2022.       distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i2dest, NULL_RTX),
  2023.                 NULL_RTX, i3, newi2pat ? i2 : NULL_RTX,
  2024.                 NULL_RTX, NULL_RTX);
  2025.       }
  2026.  
  2027.     if (i1dest_in_i1src)
  2028.       {
  2029.     if (GET_CODE (i1dest) == REG)
  2030.       reg_n_deaths[REGNO (i1dest)]++;
  2031.  
  2032.     if (newi2pat && reg_set_p (i1dest, newi2pat))
  2033.       distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i1dest, NULL_RTX),
  2034.                 NULL_RTX, i2, NULL_RTX, NULL_RTX, NULL_RTX);
  2035.     else
  2036.       distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i1dest, NULL_RTX),
  2037.                 NULL_RTX, i3, newi2pat ? i2 : NULL_RTX,
  2038.                 NULL_RTX, NULL_RTX);
  2039.       }
  2040.  
  2041.     distribute_links (i3links);
  2042.     distribute_links (i2links);
  2043.     distribute_links (i1links);
  2044.  
  2045.     if (GET_CODE (i2dest) == REG)
  2046.       {
  2047.     rtx link;
  2048.     rtx i2_insn = 0, i2_val = 0, set;
  2049.  
  2050.     /* The insn that used to set this register doesn't exist, and
  2051.        this life of the register may not exist either.  See if one of
  2052.        I3's links points to an insn that sets I2DEST.  If it does, 
  2053.        that is now the last known value for I2DEST. If we don't update
  2054.        this and I2 set the register to a value that depended on its old
  2055.        contents, we will get confused.  If this insn is used, thing
  2056.        will be set correctly in combine_instructions.  */
  2057.  
  2058.     for (link = LOG_LINKS (i3); link; link = XEXP (link, 1))
  2059.       if ((set = single_set (XEXP (link, 0))) != 0
  2060.           && rtx_equal_p (i2dest, SET_DEST (set)))
  2061.         i2_insn = XEXP (link, 0), i2_val = SET_SRC (set);
  2062.  
  2063.     record_value_for_reg (i2dest, i2_insn, i2_val);
  2064.  
  2065.     /* If the reg formerly set in I2 died only once and that was in I3,
  2066.        zero its use count so it won't make `reload' do any work.  */
  2067.     if (! added_sets_2 && newi2pat == 0)
  2068.       {
  2069.         regno = REGNO (i2dest);
  2070.         reg_n_sets[regno]--;
  2071.         if (reg_n_sets[regno] == 0
  2072.         && ! (basic_block_live_at_start[0][regno / REGSET_ELT_BITS]
  2073.               & ((REGSET_ELT_TYPE) 1 << (regno % REGSET_ELT_BITS))))
  2074.           reg_n_refs[regno] = 0;
  2075.       }
  2076.       }
  2077.  
  2078.     if (i1 && GET_CODE (i1dest) == REG)
  2079.       {
  2080.     rtx link;
  2081.     rtx i1_insn = 0, i1_val = 0, set;
  2082.  
  2083.     for (link = LOG_LINKS (i3); link; link = XEXP (link, 1))
  2084.       if ((set = single_set (XEXP (link, 0))) != 0
  2085.           && rtx_equal_p (i1dest, SET_DEST (set)))
  2086.         i1_insn = XEXP (link, 0), i1_val = SET_SRC (set);
  2087.  
  2088.     record_value_for_reg (i1dest, i1_insn, i1_val);
  2089.  
  2090.     regno = REGNO (i1dest);
  2091.     if (! added_sets_1)
  2092.       {
  2093.         reg_n_sets[regno]--;
  2094.         if (reg_n_sets[regno] == 0
  2095.         && ! (basic_block_live_at_start[0][regno / REGSET_ELT_BITS]
  2096.               & ((REGSET_ELT_TYPE) 1 << (regno % REGSET_ELT_BITS))))
  2097.           reg_n_refs[regno] = 0;
  2098.       }
  2099.       }
  2100.  
  2101.     /* Update reg_significant et al for any changes that may have been made
  2102.        to this insn.  */
  2103.  
  2104.     note_stores (newpat, set_significant);
  2105.     if (newi2pat)
  2106.       note_stores (newi2pat, set_significant);
  2107.  
  2108.     /* If I3 is now an unconditional jump, ensure that it has a 
  2109.        BARRIER following it since it may have initially been a
  2110.        conditional jump.  It may also be the last nonnote insn.  */
  2111.  
  2112.     if ((GET_CODE (newpat) == RETURN || simplejump_p (i3))
  2113.     && ((temp = next_nonnote_insn (i3)) == NULL_RTX
  2114.         || GET_CODE (temp) != BARRIER))
  2115.       emit_barrier_after (i3);
  2116.   }
  2117.  
  2118.   combine_successes++;
  2119.  
  2120.   return newi2pat ? i2 : i3;
  2121. }
  2122.  
  2123. /* Undo all the modifications recorded in undobuf.  */
  2124.  
  2125. static void
  2126. undo_all ()
  2127. {
  2128.   register int i;
  2129.   if (undobuf.num_undo > MAX_UNDO)
  2130.     undobuf.num_undo = MAX_UNDO;
  2131.   for (i = undobuf.num_undo - 1; i >= 0; i--)
  2132.     {
  2133.       if (undobuf.undo[i].is_int)
  2134.     *undobuf.undo[i].where.i = undobuf.undo[i].old_contents.i;
  2135.       else
  2136.     *undobuf.undo[i].where.rtx = undobuf.undo[i].old_contents.rtx;
  2137.       
  2138.     }
  2139.  
  2140.   obfree (undobuf.storage);
  2141.   undobuf.num_undo = 0;
  2142. }
  2143.  
  2144. /* Find the innermost point within the rtx at LOC, possibly LOC itself,
  2145.    where we have an arithmetic expression and return that point.  LOC will
  2146.    be inside INSN.
  2147.  
  2148.    try_combine will call this function to see if an insn can be split into
  2149.    two insns.  */
  2150.  
  2151. static rtx *
  2152. find_split_point (loc, insn)
  2153.      rtx *loc;
  2154.      rtx insn;
  2155. {
  2156.   rtx x = *loc;
  2157.   enum rtx_code code = GET_CODE (x);
  2158.   rtx *split;
  2159.   int len = 0, pos, unsignedp;
  2160.   rtx inner;
  2161.  
  2162.   /* First special-case some codes.  */
  2163.   switch (code)
  2164.     {
  2165.     case SUBREG:
  2166. #ifdef INSN_SCHEDULING
  2167.       /* If we are making a paradoxical SUBREG invalid, it becomes a split
  2168.      point.  */
  2169.       if (GET_CODE (SUBREG_REG (x)) == MEM)
  2170.     return loc;
  2171. #endif
  2172.       return find_split_point (&SUBREG_REG (x), insn);
  2173.  
  2174.     case MEM:
  2175. #ifdef HAVE_lo_sum
  2176.       /* If we have (mem (const ..)) or (mem (symbol_ref ...)), split it
  2177.      using LO_SUM and HIGH.  */
  2178.       if (GET_CODE (XEXP (x, 0)) == CONST
  2179.       || GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
  2180.     {
  2181.       SUBST (XEXP (x, 0),
  2182.          gen_rtx_combine (LO_SUM, Pmode,
  2183.                   gen_rtx_combine (HIGH, Pmode, XEXP (x, 0)),
  2184.                   XEXP (x, 0)));
  2185.       return &XEXP (XEXP (x, 0), 0);
  2186.     }
  2187. #endif
  2188.  
  2189.       /* If we have a PLUS whose second operand is a constant and the
  2190.      address is not valid, perhaps will can split it up using
  2191.      the machine-specific way to split large constants.  We use
  2192.      the first psuedo-reg (one of the virtual regs) as a placeholder;
  2193.      it will not remain in the result.  */
  2194.       if (GET_CODE (XEXP (x, 0)) == PLUS
  2195.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  2196.       && ! memory_address_p (GET_MODE (x), XEXP (x, 0)))
  2197.     {
  2198.       rtx reg = regno_reg_rtx[FIRST_PSEUDO_REGISTER];
  2199.       rtx seq = split_insns (gen_rtx (SET, VOIDmode, reg, XEXP (x, 0)),
  2200.                  subst_insn);
  2201.  
  2202.       /* This should have produced two insns, each of which sets our
  2203.          placeholder.  If the source of the second is a valid address,
  2204.          we can make put both sources together and make a split point
  2205.          in the middle.  */
  2206.  
  2207.       if (seq && XVECLEN (seq, 0) == 2
  2208.           && GET_CODE (XVECEXP (seq, 0, 0)) == INSN
  2209.           && GET_CODE (PATTERN (XVECEXP (seq, 0, 0))) == SET
  2210.           && SET_DEST (PATTERN (XVECEXP (seq, 0, 0))) == reg
  2211.           && ! reg_mentioned_p (reg,
  2212.                     SET_SRC (PATTERN (XVECEXP (seq, 0, 0))))
  2213.           && GET_CODE (XVECEXP (seq, 0, 1)) == INSN
  2214.           && GET_CODE (PATTERN (XVECEXP (seq, 0, 1))) == SET
  2215.           && SET_DEST (PATTERN (XVECEXP (seq, 0, 1))) == reg
  2216.           && memory_address_p (GET_MODE (x),
  2217.                    SET_SRC (PATTERN (XVECEXP (seq, 0, 1)))))
  2218.         {
  2219.           rtx src1 = SET_SRC (PATTERN (XVECEXP (seq, 0, 0)));
  2220.           rtx src2 = SET_SRC (PATTERN (XVECEXP (seq, 0, 1)));
  2221.  
  2222.           /* Replace the placeholder in SRC2 with SRC1.  If we can
  2223.          find where in SRC2 it was placed, that can become our
  2224.          split point and we can replace this address with SRC2.
  2225.          Just try two obvious places.  */
  2226.  
  2227.           src2 = replace_rtx (src2, reg, src1);
  2228.           split = 0;
  2229.           if (XEXP (src2, 0) == src1)
  2230.         split = &XEXP (src2, 0);
  2231.           else if (GET_RTX_FORMAT (GET_CODE (XEXP (src2, 0)))[0] == 'e'
  2232.                && XEXP (XEXP (src2, 0), 0) == src1)
  2233.         split = &XEXP (XEXP (src2, 0), 0);
  2234.  
  2235.           if (split)
  2236.         {
  2237.           SUBST (XEXP (x, 0), src2);
  2238.           return split;
  2239.         }
  2240.         }
  2241.       
  2242.       /* If that didn't work, perhaps the first operand is complex and
  2243.          needs to be computed separately, so make a split point there.
  2244.          This will occur on machines that just support REG + CONST
  2245.          and have a constant moved through some previous computation.  */
  2246.  
  2247.       else if (GET_RTX_CLASS (GET_CODE (XEXP (XEXP (x, 0), 0))) != 'o'
  2248.            && ! (GET_CODE (XEXP (XEXP (x, 0), 0)) == SUBREG
  2249.              && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (XEXP (x, 0), 0))))
  2250.                  == 'o')))
  2251.         return &XEXP (XEXP (x, 0), 0);
  2252.     }
  2253.       break;
  2254.  
  2255.     case SET:
  2256. #ifdef HAVE_cc0
  2257.       /* If SET_DEST is CC0 and SET_SRC is not an operand, a COMPARE, or a
  2258.      ZERO_EXTRACT, the most likely reason why this doesn't match is that
  2259.      we need to put the operand into a register.  So split at that
  2260.      point.  */
  2261.  
  2262.       if (SET_DEST (x) == cc0_rtx
  2263.       && GET_CODE (SET_SRC (x)) != COMPARE
  2264.       && GET_CODE (SET_SRC (x)) != ZERO_EXTRACT
  2265.       && GET_RTX_CLASS (GET_CODE (SET_SRC (x))) != 'o'
  2266.       && ! (GET_CODE (SET_SRC (x)) == SUBREG
  2267.         && GET_RTX_CLASS (GET_CODE (SUBREG_REG (SET_SRC (x)))) == 'o'))
  2268.     return &SET_SRC (x);
  2269. #endif
  2270.  
  2271.       /* See if we can split SET_SRC as it stands.  */
  2272.       split = find_split_point (&SET_SRC (x), insn);
  2273.       if (split && split != &SET_SRC (x))
  2274.     return split;
  2275.  
  2276.       /* See if this is a bitfield assignment with everything constant.  If
  2277.      so, this is an IOR of an AND, so split it into that.  */
  2278.       if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
  2279.       && (GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
  2280.           <= HOST_BITS_PER_WIDE_INT)
  2281.       && GET_CODE (XEXP (SET_DEST (x), 1)) == CONST_INT
  2282.       && GET_CODE (XEXP (SET_DEST (x), 2)) == CONST_INT
  2283.       && GET_CODE (SET_SRC (x)) == CONST_INT
  2284.       && ((INTVAL (XEXP (SET_DEST (x), 1))
  2285.           + INTVAL (XEXP (SET_DEST (x), 2)))
  2286.           <= GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x), 0))))
  2287.       && ! side_effects_p (XEXP (SET_DEST (x), 0)))
  2288.     {
  2289.       int pos = INTVAL (XEXP (SET_DEST (x), 2));
  2290.       int len = INTVAL (XEXP (SET_DEST (x), 1));
  2291.       int src = INTVAL (SET_SRC (x));
  2292.       rtx dest = XEXP (SET_DEST (x), 0);
  2293.       enum machine_mode mode = GET_MODE (dest);
  2294.       unsigned HOST_WIDE_INT mask = ((HOST_WIDE_INT) 1 << len) - 1;
  2295.  
  2296. #if BITS_BIG_ENDIAN
  2297.       pos = GET_MODE_BITSIZE (mode) - len - pos;
  2298. #endif
  2299.  
  2300.       if (src == mask)
  2301.         SUBST (SET_SRC (x),
  2302.            gen_binary (IOR, mode, dest, GEN_INT (src << pos)));
  2303.       else
  2304.         SUBST (SET_SRC (x),
  2305.            gen_binary (IOR, mode,
  2306.                    gen_binary (AND, mode, dest, 
  2307.                        GEN_INT (~ (mask << pos)
  2308.                             & GET_MODE_MASK (mode))),
  2309.                    GEN_INT (src << pos)));
  2310.  
  2311.       SUBST (SET_DEST (x), dest);
  2312.  
  2313.       split = find_split_point (&SET_SRC (x), insn);
  2314.       if (split && split != &SET_SRC (x))
  2315.         return split;
  2316.     }
  2317.  
  2318.       /* Otherwise, see if this is an operation that we can split into two.
  2319.      If so, try to split that.  */
  2320.       code = GET_CODE (SET_SRC (x));
  2321.  
  2322.       switch (code)
  2323.     {
  2324.     case AND:
  2325.       /* If we are AND'ing with a large constant that is only a single
  2326.          bit and the result is only being used in a context where we
  2327.          need to know if it is zero or non-zero, replace it with a bit
  2328.          extraction.  This will avoid the large constant, which might
  2329.          have taken more than one insn to make.  If the constant were
  2330.          not a valid argument to the AND but took only one insn to make,
  2331.          this is no worse, but if it took more than one insn, it will
  2332.          be better.  */
  2333.  
  2334.       if (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
  2335.           && GET_CODE (XEXP (SET_SRC (x), 0)) == REG
  2336.           && (pos = exact_log2 (INTVAL (XEXP (SET_SRC (x), 1)))) >= 7
  2337.           && GET_CODE (SET_DEST (x)) == REG
  2338.           && (split = find_single_use (SET_DEST (x), insn, NULL_PTR)) != 0
  2339.           && (GET_CODE (*split) == EQ || GET_CODE (*split) == NE)
  2340.           && XEXP (*split, 0) == SET_DEST (x)
  2341.           && XEXP (*split, 1) == const0_rtx)
  2342.         {
  2343.           SUBST (SET_SRC (x),
  2344.              make_extraction (GET_MODE (SET_DEST (x)),
  2345.                       XEXP (SET_SRC (x), 0),
  2346.                       pos, NULL_RTX, 1, 1, 0, 0));
  2347.           return find_split_point (loc, insn);
  2348.         }
  2349.       break;
  2350.  
  2351.     case SIGN_EXTEND:
  2352.       inner = XEXP (SET_SRC (x), 0);
  2353.       pos = 0;
  2354.       len = GET_MODE_BITSIZE (GET_MODE (inner));
  2355.       unsignedp = 0;
  2356.       break;
  2357.  
  2358.     case SIGN_EXTRACT:
  2359.     case ZERO_EXTRACT:
  2360.       if (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
  2361.           && GET_CODE (XEXP (SET_SRC (x), 2)) == CONST_INT)
  2362.         {
  2363.           inner = XEXP (SET_SRC (x), 0);
  2364.           len = INTVAL (XEXP (SET_SRC (x), 1));
  2365.           pos = INTVAL (XEXP (SET_SRC (x), 2));
  2366.  
  2367. #if BITS_BIG_ENDIAN
  2368.           pos = GET_MODE_BITSIZE (GET_MODE (inner)) - len - pos;
  2369. #endif
  2370.           unsignedp = (code == ZERO_EXTRACT);
  2371.         }
  2372.       break;
  2373.     }
  2374.  
  2375.       if (len && pos >= 0 && pos + len <= GET_MODE_BITSIZE (GET_MODE (inner)))
  2376.     {
  2377.       enum machine_mode mode = GET_MODE (SET_SRC (x));
  2378.  
  2379.       /* For unsigned, we have a choice of a shift followed by an
  2380.          AND or two shifts.  Use two shifts for field sizes where the
  2381.          constant might be too large.  We assume here that we can
  2382.          always at least get 8-bit constants in an AND insn, which is
  2383.          true for every current RISC.  */
  2384.  
  2385.       if (unsignedp && len <= 8)
  2386.         {
  2387.           SUBST (SET_SRC (x),
  2388.              gen_rtx_combine
  2389.              (AND, mode,
  2390.               gen_rtx_combine (LSHIFTRT, mode,
  2391.                        gen_lowpart_for_combine (mode, inner),
  2392.                        GEN_INT (pos)),
  2393.               GEN_INT (((HOST_WIDE_INT) 1 << len) - 1)));
  2394.  
  2395.           split = find_split_point (&SET_SRC (x), insn);
  2396.           if (split && split != &SET_SRC (x))
  2397.         return split;
  2398.         }
  2399.       else
  2400.         {
  2401.           SUBST (SET_SRC (x),
  2402.              gen_rtx_combine
  2403.              (unsignedp ? LSHIFTRT : ASHIFTRT, mode,
  2404.               gen_rtx_combine (ASHIFT, mode,
  2405.                        gen_lowpart_for_combine (mode, inner),
  2406.                        GEN_INT (GET_MODE_BITSIZE (mode)
  2407.                         - len - pos)),
  2408.               GEN_INT (GET_MODE_BITSIZE (mode) - len)));
  2409.  
  2410.           split = find_split_point (&SET_SRC (x), insn);
  2411.           if (split && split != &SET_SRC (x))
  2412.         return split;
  2413.         }
  2414.     }
  2415.  
  2416.       /* See if this is a simple operation with a constant as the second
  2417.      operand.  It might be that this constant is out of range and hence
  2418.      could be used as a split point.  */
  2419.       if ((GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '2'
  2420.        || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == 'c'
  2421.        || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '<')
  2422.       && CONSTANT_P (XEXP (SET_SRC (x), 1))
  2423.       && (GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (x), 0))) == 'o'
  2424.           || (GET_CODE (XEXP (SET_SRC (x), 0)) == SUBREG
  2425.           && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (SET_SRC (x), 0))))
  2426.               == 'o'))))
  2427.     return &XEXP (SET_SRC (x), 1);
  2428.  
  2429.       /* Finally, see if this is a simple operation with its first operand
  2430.      not in a register.  The operation might require this operand in a
  2431.      register, so return it as a split point.  We can always do this
  2432.      because if the first operand were another operation, we would have
  2433.      already found it as a split point.  */
  2434.       if ((GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '2'
  2435.        || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == 'c'
  2436.        || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '<'
  2437.        || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '1')
  2438.       && ! register_operand (XEXP (SET_SRC (x), 0), VOIDmode))
  2439.     return &XEXP (SET_SRC (x), 0);
  2440.  
  2441.       return 0;
  2442.  
  2443.     case AND:
  2444.     case IOR:
  2445.       /* We write NOR as (and (not A) (not B)), but if we don't have a NOR,
  2446.      it is better to write this as (not (ior A B)) so we can split it.
  2447.      Similarly for IOR.  */
  2448.       if (GET_CODE (XEXP (x, 0)) == NOT && GET_CODE (XEXP (x, 1)) == NOT)
  2449.     {
  2450.       SUBST (*loc,
  2451.          gen_rtx_combine (NOT, GET_MODE (x),
  2452.                   gen_rtx_combine (code == IOR ? AND : IOR,
  2453.                            GET_MODE (x),
  2454.                            XEXP (XEXP (x, 0), 0),
  2455.                            XEXP (XEXP (x, 1), 0))));
  2456.       return find_split_point (loc, insn);
  2457.     }
  2458.  
  2459.       /* Many RISC machines have a large set of logical insns.  If the
  2460.      second operand is a NOT, put it first so we will try to split the
  2461.      other operand first.  */
  2462.       if (GET_CODE (XEXP (x, 1)) == NOT)
  2463.     {
  2464.       rtx tem = XEXP (x, 0);
  2465.       SUBST (XEXP (x, 0), XEXP (x, 1));
  2466.       SUBST (XEXP (x, 1), tem);
  2467.     }
  2468.       break;
  2469.     }
  2470.  
  2471.   /* Otherwise, select our actions depending on our rtx class.  */
  2472.   switch (GET_RTX_CLASS (code))
  2473.     {
  2474.     case 'b':            /* This is ZERO_EXTRACT and SIGN_EXTRACT.  */
  2475.     case '3':
  2476.       split = find_split_point (&XEXP (x, 2), insn);
  2477.       if (split)
  2478.     return split;
  2479.       /* ... fall through ... */
  2480.     case '2':
  2481.     case 'c':
  2482.     case '<':
  2483.       split = find_split_point (&XEXP (x, 1), insn);
  2484.       if (split)
  2485.     return split;
  2486.       /* ... fall through ... */
  2487.     case '1':
  2488.       /* Some machines have (and (shift ...) ...) insns.  If X is not
  2489.      an AND, but XEXP (X, 0) is, use it as our split point.  */
  2490.       if (GET_CODE (x) != AND && GET_CODE (XEXP (x, 0)) == AND)
  2491.     return &XEXP (x, 0);
  2492.  
  2493.       split = find_split_point (&XEXP (x, 0), insn);
  2494.       if (split)
  2495.     return split;
  2496.       return loc;
  2497.     }
  2498.  
  2499.   /* Otherwise, we don't have a split point.  */
  2500.   return 0;
  2501. }
  2502.  
  2503. #ifdef MPW
  2504. #pragma segment COMB01
  2505. #endif
  2506. /* Throughout X, replace FROM with TO, and return the result.
  2507.    The result is TO if X is FROM;
  2508.    otherwise the result is X, but its contents may have been modified.
  2509.    If they were modified, a record was made in undobuf so that
  2510.    undo_all will (among other things) return X to its original state.
  2511.  
  2512.    If the number of changes necessary is too much to record to undo,
  2513.    the excess changes are not made, so the result is invalid.
  2514.    The changes already made can still be undone.
  2515.    undobuf.num_undo is incremented for such changes, so by testing that
  2516.    the caller can tell whether the result is valid.
  2517.  
  2518.    `n_occurrences' is incremented each time FROM is replaced.
  2519.    
  2520.    IN_DEST is non-zero if we are processing the SET_DEST of a SET.
  2521.  
  2522.    UNIQUE_COPY is non-zero if each substitution must be unique.  We do this
  2523.    by copying if `n_occurrences' is non-zero.  */
  2524.  
  2525. static rtx
  2526. subst (x, from, to, in_dest, unique_copy)
  2527.      register rtx x, from, to;
  2528.      int in_dest;
  2529.      int unique_copy;
  2530. {
  2531.   register char *fmt;
  2532.   register int len, i;
  2533.   register enum rtx_code code = GET_CODE (x), orig_code = code;
  2534.   rtx temp;
  2535.   enum machine_mode mode = GET_MODE (x);
  2536.   enum machine_mode op0_mode = VOIDmode;
  2537.   rtx other_insn;
  2538.   rtx *cc_use;
  2539.   int n_restarts = 0;
  2540.  
  2541. /* FAKE_EXTEND_SAFE_P (MODE, FROM) is 1 if (subreg:MODE FROM 0) is a safe
  2542.    replacement for (zero_extend:MODE FROM) or (sign_extend:MODE FROM).
  2543.    If it is 0, that cannot be done.  We can now do this for any MEM
  2544.    because (SUBREG (MEM...)) is guaranteed to cause the MEM to be reloaded.
  2545.    If not for that, MEM's would very rarely be safe.  */
  2546.  
  2547. /* Reject MODEs bigger than a word, because we might not be able
  2548.    to reference a two-register group starting with an arbitrary register
  2549.    (and currently gen_lowpart might crash for a SUBREG).  */
  2550.  
  2551. #define FAKE_EXTEND_SAFE_P(MODE, FROM) \
  2552.   (GET_MODE_SIZE (MODE) <= UNITS_PER_WORD)
  2553.  
  2554. /* Two expressions are equal if they are identical copies of a shared
  2555.    RTX or if they are both registers with the same register number
  2556.    and mode.  */
  2557.  
  2558. #define COMBINE_RTX_EQUAL_P(X,Y)            \
  2559.   ((X) == (Y)                        \
  2560.    || (GET_CODE (X) == REG && GET_CODE (Y) == REG    \
  2561.        && REGNO (X) == REGNO (Y) && GET_MODE (X) == GET_MODE (Y)))
  2562.  
  2563.   if (! in_dest && COMBINE_RTX_EQUAL_P (x, from))
  2564.     {
  2565.       n_occurrences++;
  2566.       return (unique_copy && n_occurrences > 1 ? copy_rtx (to) : to);
  2567.     }
  2568.  
  2569.   /* If X and FROM are the same register but different modes, they will
  2570.      not have been seen as equal above.  However, flow.c will make a 
  2571.      LOG_LINKS entry for that case.  If we do nothing, we will try to
  2572.      rerecognize our original insn and, when it succeeds, we will
  2573.      delete the feeding insn, which is incorrect.
  2574.  
  2575.      So force this insn not to match in this (rare) case.  */
  2576.   if (! in_dest && code == REG && GET_CODE (from) == REG
  2577.       && REGNO (x) == REGNO (from))
  2578.     return gen_rtx (CLOBBER, GET_MODE (x), const0_rtx);
  2579.  
  2580.   /* If this is an object, we are done unless it is a MEM or LO_SUM, both
  2581.      of which may contain things that can be combined.  */
  2582.   if (code != MEM && code != LO_SUM && GET_RTX_CLASS (code) == 'o')
  2583.     return x;
  2584.  
  2585.   /* It is possible to have a subexpression appear twice in the insn.
  2586.      Suppose that FROM is a register that appears within TO.
  2587.      Then, after that subexpression has been scanned once by `subst',
  2588.      the second time it is scanned, TO may be found.  If we were
  2589.      to scan TO here, we would find FROM within it and create a
  2590.      self-referent rtl structure which is completely wrong.  */
  2591.   if (COMBINE_RTX_EQUAL_P (x, to))
  2592.     return to;
  2593.  
  2594.   len = GET_RTX_LENGTH (code);
  2595.   fmt = GET_RTX_FORMAT (code);
  2596.  
  2597.   /* We don't need to process a SET_DEST that is a register, CC0, or PC, so
  2598.      set up to skip this common case.  All other cases where we want to
  2599.      suppress replacing something inside a SET_SRC are handled via the
  2600.      IN_DEST operand.  */
  2601.   if (code == SET
  2602.       && (GET_CODE (SET_DEST (x)) == REG
  2603.         || GET_CODE (SET_DEST (x)) == CC0
  2604.         || GET_CODE (SET_DEST (x)) == PC))
  2605.     fmt = "ie";
  2606.  
  2607.   /* Get the mode of operand 0 in case X is now a SIGN_EXTEND of a constant. */
  2608.   if (fmt[0] == 'e')
  2609.     op0_mode = GET_MODE (XEXP (x, 0));
  2610.  
  2611.   for (i = 0; i < len; i++)
  2612.     {
  2613.       if (fmt[i] == 'E')
  2614.     {
  2615.       register int j;
  2616.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2617.         {
  2618.           register rtx new;
  2619.           if (COMBINE_RTX_EQUAL_P (XVECEXP (x, i, j), from))
  2620.         {
  2621.           new = (unique_copy && n_occurrences ? copy_rtx (to) : to);
  2622.           n_occurrences++;
  2623.         }
  2624.           else
  2625.         {
  2626.           new = subst (XVECEXP (x, i, j), from, to, 0, unique_copy);
  2627.  
  2628.           /* If this substitution failed, this whole thing fails.  */
  2629.           if (GET_CODE (new) == CLOBBER && XEXP (new, 0) == const0_rtx)
  2630.             return new;
  2631.         }
  2632.  
  2633.           SUBST (XVECEXP (x, i, j), new);
  2634.         }
  2635.     }
  2636.       else if (fmt[i] == 'e')
  2637.     {
  2638.       register rtx new;
  2639.  
  2640.       if (COMBINE_RTX_EQUAL_P (XEXP (x, i), from))
  2641.         {
  2642.           new = (unique_copy && n_occurrences ? copy_rtx (to) : to);
  2643.           n_occurrences++;
  2644.         }
  2645.       else
  2646.         /* If we are in a SET_DEST, suppress most cases unless we
  2647.            have gone inside a MEM, in which case we want to
  2648.            simplify the address.  We assume here that things that
  2649.            are actually part of the destination have their inner
  2650.            parts in the first expression.  This is true for SUBREG, 
  2651.            STRICT_LOW_PART, and ZERO_EXTRACT, which are the only
  2652.            things aside from REG and MEM that should appear in a
  2653.            SET_DEST.  */
  2654.         new = subst (XEXP (x, i), from, to,
  2655.              (((in_dest
  2656.                 && (code == SUBREG || code == STRICT_LOW_PART
  2657.                 || code == ZERO_EXTRACT))
  2658.                || code == SET)
  2659.               && i == 0), unique_copy);
  2660.  
  2661.       /* If we found that we will have to reject this combination,
  2662.          indicate that by returning the CLOBBER ourselves, rather than
  2663.          an expression containing it.  This will speed things up as
  2664.          well as prevent accidents where two CLOBBERs are considered
  2665.          to be equal, thus producing an incorrect simplification.  */
  2666.  
  2667.       if (GET_CODE (new) == CLOBBER && XEXP (new, 0) == const0_rtx)
  2668.         return new;
  2669.  
  2670.       SUBST (XEXP (x, i), new);
  2671.     }
  2672.     }
  2673.  
  2674.   /* We come back to here if we have replaced the expression with one of
  2675.      a different code and it is likely that further simplification will be
  2676.      possible.  */
  2677.  
  2678.  restart:
  2679.  
  2680.   /* If we have restarted more than 4 times, we are probably looping, so
  2681.      give up.  */
  2682.   if (++n_restarts > 4)
  2683.     return x;
  2684.  
  2685.   /* If we are restarting at all, it means that we no longer know the
  2686.      original mode of operand 0 (since we have probably changed the
  2687.      form of X).  */
  2688.  
  2689.   if (n_restarts > 1)
  2690.     op0_mode = VOIDmode;
  2691.  
  2692.   code = GET_CODE (x);
  2693.  
  2694.   /* If this is a commutative operation, put a constant last and a complex
  2695.      expression first.  We don't need to do this for comparisons here.  */
  2696.   if (GET_RTX_CLASS (code) == 'c'
  2697.       && ((CONSTANT_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) != CONST_INT)
  2698.       || (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == 'o'
  2699.           && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) != 'o')
  2700.       || (GET_CODE (XEXP (x, 0)) == SUBREG
  2701.           && GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0)))) == 'o'
  2702.           && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) != 'o')))
  2703.     {
  2704.       temp = XEXP (x, 0);
  2705.       SUBST (XEXP (x, 0), XEXP (x, 1));
  2706.       SUBST (XEXP (x, 1), temp);
  2707.     }
  2708.  
  2709.   /* If this is a PLUS, MINUS, or MULT, and the first operand is the
  2710.      sign extension of a PLUS with a constant, reverse the order of the sign
  2711.      extension and the addition. Note that this not the same as the original
  2712.      code, but overflow is undefined for signed values.  Also note that the
  2713.      PLUS will have been partially moved "inside" the sign-extension, so that
  2714.      the first operand of X will really look like:
  2715.          (ashiftrt (plus (ashift A C4) C5) C4).
  2716.      We convert this to
  2717.          (plus (ashiftrt (ashift A C4) C2) C4)
  2718.      and replace the first operand of X with that expression.  Later parts
  2719.      of this function may simplify the expression further.
  2720.  
  2721.      For example, if we start with (mult (sign_extend (plus A C1)) C2),
  2722.      we swap the SIGN_EXTEND and PLUS.  Later code will apply the
  2723.      distributive law to produce (plus (mult (sign_extend X) C1) C3).
  2724.  
  2725.      We do this to simplify address expressions.  */
  2726.  
  2727.   if ((code == PLUS || code == MINUS || code == MULT)
  2728.       && GET_CODE (XEXP (x, 0)) == ASHIFTRT
  2729.       && GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS
  2730.       && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ASHIFT
  2731.       && GET_CODE (XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 1)) == CONST_INT
  2732.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  2733.       && XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 1) == XEXP (XEXP (x, 0), 1)
  2734.       && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
  2735.       && (temp = simplify_binary_operation (ASHIFTRT, mode,
  2736.                         XEXP (XEXP (XEXP (x, 0), 0), 1),
  2737.                         XEXP (XEXP (x, 0), 1))) != 0)
  2738.     {
  2739.       rtx new
  2740.     = simplify_shift_const (NULL_RTX, ASHIFT, mode,
  2741.                 XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 0),
  2742.                 INTVAL (XEXP (XEXP (x, 0), 1)));
  2743.  
  2744.       new = simplify_shift_const (NULL_RTX, ASHIFTRT, mode, new,
  2745.                   INTVAL (XEXP (XEXP (x, 0), 1)));
  2746.  
  2747.       SUBST (XEXP (x, 0), gen_binary (PLUS, mode, new, temp));
  2748.     }
  2749.  
  2750.   /* If this is a simple operation applied to an IF_THEN_ELSE, try 
  2751.      applying it to the arms of the IF_THEN_ELSE.  This often simplifies
  2752.      things.  Don't deal with operations that change modes here.  */
  2753.  
  2754.   if ((GET_RTX_CLASS (code) == '2' || GET_RTX_CLASS (code) == 'c')
  2755.       && GET_CODE (XEXP (x, 0)) == IF_THEN_ELSE)
  2756.     {
  2757.       /* Don't do this by using SUBST inside X since we might be messing
  2758.      up a shared expression.  */
  2759.       rtx cond = XEXP (XEXP (x, 0), 0);
  2760.       rtx t_arm = subst (gen_binary (code, mode, XEXP (XEXP (x, 0), 1),
  2761.                      XEXP (x, 1)),
  2762.              pc_rtx, pc_rtx, 0, 0);
  2763.       rtx f_arm = subst (gen_binary (code, mode, XEXP (XEXP (x, 0), 2),
  2764.                      XEXP (x, 1)),
  2765.              pc_rtx, pc_rtx, 0, 0);
  2766.  
  2767.  
  2768.       x = gen_rtx (IF_THEN_ELSE, mode, cond, t_arm, f_arm);
  2769.       goto restart;
  2770.     }
  2771.  
  2772.   else if (GET_RTX_CLASS (code) == '1'
  2773.        && GET_CODE (XEXP (x, 0)) == IF_THEN_ELSE
  2774.        && GET_MODE (XEXP (x, 0)) == mode)
  2775.     {
  2776.       rtx cond = XEXP (XEXP (x, 0), 0);
  2777.       rtx t_arm = subst (gen_unary (code, mode, XEXP (XEXP (x, 0), 1)),
  2778.              pc_rtx, pc_rtx, 0, 0);
  2779.       rtx f_arm = subst (gen_unary (code, mode, XEXP (XEXP (x, 0), 2)),
  2780.              pc_rtx, pc_rtx, 0, 0);
  2781.  
  2782.       x = gen_rtx_combine (IF_THEN_ELSE, mode, cond, t_arm, f_arm);
  2783.       goto restart;
  2784.     }
  2785.  
  2786.   /* Try to fold this expression in case we have constants that weren't
  2787.      present before.  */
  2788.   temp = 0;
  2789.   switch (GET_RTX_CLASS (code))
  2790.     {
  2791.     case '1':
  2792.       temp = simplify_unary_operation (code, mode, XEXP (x, 0), op0_mode);
  2793.       break;
  2794.     case '<':
  2795.       temp = simplify_relational_operation (code, op0_mode,
  2796.                         XEXP (x, 0), XEXP (x, 1));
  2797. #ifdef FLOAT_STORE_FLAG_VALUE
  2798.       if (temp != 0 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
  2799.     temp = ((temp == const0_rtx) ? CONST0_RTX (GET_MODE (x))
  2800.         : immed_real_const_1 (FLOAT_STORE_FLAG_VALUE, GET_MODE (x)));
  2801. #endif
  2802.       break;
  2803.     case 'c':
  2804.     case '2':
  2805.       temp = simplify_binary_operation (code, mode, XEXP (x, 0), XEXP (x, 1));
  2806.       break;
  2807.     case 'b':
  2808.     case '3':
  2809.       temp = simplify_ternary_operation (code, mode, op0_mode, XEXP (x, 0),
  2810.                      XEXP (x, 1), XEXP (x, 2));
  2811.       break;
  2812.     }
  2813.  
  2814.   if (temp)
  2815.     x = temp, code = GET_CODE (temp);
  2816.  
  2817.   /* First see if we can apply the inverse distributive law.  */
  2818.   if (code == PLUS || code == MINUS || code == IOR || code == XOR)
  2819.     {
  2820.       x = apply_distributive_law (x);
  2821.       code = GET_CODE (x);
  2822.     }
  2823.  
  2824.   /* If CODE is an associative operation not otherwise handled, see if we
  2825.      can associate some operands.  This can win if they are constants or
  2826.      if they are logically related (i.e. (a & b) & a.  */
  2827.   if ((code == PLUS || code == MINUS
  2828.        || code == MULT || code == AND || code == IOR || code == XOR
  2829.        || code == DIV || code == UDIV
  2830.        || code == SMAX || code == SMIN || code == UMAX || code == UMIN)
  2831.       && GET_MODE_CLASS (mode) == MODE_INT)
  2832.     {
  2833.       if (GET_CODE (XEXP (x, 0)) == code)
  2834.     {
  2835.       rtx other = XEXP (XEXP (x, 0), 0);
  2836.       rtx inner_op0 = XEXP (XEXP (x, 0), 1);
  2837.       rtx inner_op1 = XEXP (x, 1);
  2838.       rtx inner;
  2839.       
  2840.       /* Make sure we pass the constant operand if any as the second
  2841.          one if this is a commutative operation.  */
  2842.       if (CONSTANT_P (inner_op0) && GET_RTX_CLASS (code) == 'c')
  2843.         {
  2844.           rtx tem = inner_op0;
  2845.           inner_op0 = inner_op1;
  2846.           inner_op1 = tem;
  2847.         }
  2848.       inner = simplify_binary_operation (code == MINUS ? PLUS
  2849.                          : code == DIV ? MULT
  2850.                          : code == UDIV ? MULT
  2851.                          : code,
  2852.                          mode, inner_op0, inner_op1);
  2853.  
  2854.       /* For commutative operations, try the other pair if that one
  2855.          didn't simplify.  */
  2856.       if (inner == 0 && GET_RTX_CLASS (code) == 'c')
  2857.         {
  2858.           other = XEXP (XEXP (x, 0), 1);
  2859.           inner = simplify_binary_operation (code, mode,
  2860.                          XEXP (XEXP (x, 0), 0),
  2861.                          XEXP (x, 1));
  2862.         }
  2863.  
  2864.       if (inner)
  2865.         {
  2866.           x = gen_binary (code, mode, other, inner);
  2867.           goto restart;
  2868.         
  2869.         }
  2870.     }
  2871.     }
  2872.  
  2873.   /* A little bit of algebraic simplification here.  */
  2874.   switch (code)
  2875.     {
  2876.     case MEM:
  2877.       /* Ensure that our address has any ASHIFTs converted to MULT in case
  2878.      address-recognizing predicates are called later.  */
  2879.       temp = make_compound_operation (XEXP (x, 0), MEM);
  2880.       SUBST (XEXP (x, 0), temp);
  2881.       break;
  2882.  
  2883.     case SUBREG:
  2884.       /* (subreg:A (mem:B X) N) becomes a modified MEM unless the SUBREG
  2885.      is paradoxical.  If we can't do that safely, then it becomes
  2886.      something nonsensical so that this combination won't take place.  */
  2887.  
  2888.       if (GET_CODE (SUBREG_REG (x)) == MEM
  2889.       && (GET_MODE_SIZE (mode)
  2890.           <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
  2891.     {
  2892.       rtx inner = SUBREG_REG (x);
  2893.       int endian_offset = 0;
  2894.       /* Don't change the mode of the MEM
  2895.          if that would change the meaning of the address.  */
  2896.       if (MEM_VOLATILE_P (SUBREG_REG (x))
  2897.           || mode_dependent_address_p (XEXP (inner, 0)))
  2898.         return gen_rtx (CLOBBER, mode, const0_rtx);
  2899.  
  2900. #if BYTES_BIG_ENDIAN
  2901.       if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
  2902.         endian_offset += UNITS_PER_WORD - GET_MODE_SIZE (mode);
  2903.       if (GET_MODE_SIZE (GET_MODE (inner)) < UNITS_PER_WORD)
  2904.         endian_offset -= UNITS_PER_WORD - GET_MODE_SIZE (GET_MODE (inner));
  2905. #endif
  2906.       /* Note if the plus_constant doesn't make a valid address
  2907.          then this combination won't be accepted.  */
  2908.       x = gen_rtx (MEM, mode,
  2909.                plus_constant (XEXP (inner, 0),
  2910.                       (SUBREG_WORD (x) * UNITS_PER_WORD
  2911.                        + endian_offset)));
  2912.       MEM_VOLATILE_P (x) = MEM_VOLATILE_P (inner);
  2913.       RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (inner);
  2914.       MEM_IN_STRUCT_P (x) = MEM_IN_STRUCT_P (inner);
  2915.       return x;
  2916.     }
  2917.  
  2918.       /* If we are in a SET_DEST, these other cases can't apply.  */
  2919.       if (in_dest)
  2920.     return x;
  2921.  
  2922.       /* Changing mode twice with SUBREG => just change it once,
  2923.      or not at all if changing back to starting mode.  */
  2924.       if (GET_CODE (SUBREG_REG (x)) == SUBREG)
  2925.     {
  2926.       if (mode == GET_MODE (SUBREG_REG (SUBREG_REG (x)))
  2927.           && SUBREG_WORD (x) == 0 && SUBREG_WORD (SUBREG_REG (x)) == 0)
  2928.         return SUBREG_REG (SUBREG_REG (x));
  2929.  
  2930.       SUBST_INT (SUBREG_WORD (x),
  2931.              SUBREG_WORD (x) + SUBREG_WORD (SUBREG_REG (x)));
  2932.       SUBST (SUBREG_REG (x), SUBREG_REG (SUBREG_REG (x)));
  2933.     }
  2934.  
  2935.       /* SUBREG of a hard register => just change the register number
  2936.      and/or mode.  If the hard register is not valid in that mode,
  2937.      suppress this combination.  If the hard register is the stack,
  2938.      frame, or argument pointer, leave this as a SUBREG.  */
  2939.  
  2940.       if (GET_CODE (SUBREG_REG (x)) == REG
  2941.       && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER
  2942.       && REGNO (SUBREG_REG (x)) != FRAME_POINTER_REGNUM
  2943. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2944.       && REGNO (SUBREG_REG (x)) != ARG_POINTER_REGNUM
  2945. #endif
  2946.       && REGNO (SUBREG_REG (x)) != STACK_POINTER_REGNUM)
  2947.     {
  2948.       if (HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (x)) + SUBREG_WORD (x),
  2949.                   mode))
  2950.         return gen_rtx (REG, mode,
  2951.                 REGNO (SUBREG_REG (x)) + SUBREG_WORD (x));
  2952.       else
  2953.         return gen_rtx (CLOBBER, mode, const0_rtx);
  2954.     }
  2955.  
  2956.       /* For a constant, try to pick up the part we want.  Handle a full
  2957.      word and low-order part.  Only do this if we are narrowing
  2958.      the constant; if it is being widened, we have no idea what
  2959.      the extra bits will have been set to.  */
  2960.  
  2961.       if (CONSTANT_P (SUBREG_REG (x)) && op0_mode != VOIDmode
  2962.       && GET_MODE_SIZE (mode) == UNITS_PER_WORD
  2963.       && GET_MODE_SIZE (op0_mode) < UNITS_PER_WORD
  2964.       && GET_MODE_CLASS (mode) == MODE_INT)
  2965.     {
  2966.       temp = operand_subword (SUBREG_REG (x), SUBREG_WORD (x),
  2967.                   0, op0_mode);
  2968.       if (temp)
  2969.         return temp;
  2970.     }
  2971.     
  2972.       if (CONSTANT_P (SUBREG_REG (x)) && subreg_lowpart_p (x)
  2973.       && GET_MODE_SIZE (mode) < GET_MODE_SIZE (op0_mode))
  2974.     return gen_lowpart_for_combine (mode, SUBREG_REG (x));
  2975.  
  2976.       /* If we are narrowing the object, we need to see if we can simplify
  2977.      the expression for the object knowing that we only need the
  2978.      low-order bits.  */
  2979.  
  2980.       if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
  2981.       && subreg_lowpart_p (x))
  2982.     return force_to_mode (SUBREG_REG (x), mode, GET_MODE_BITSIZE (mode),
  2983.                   NULL_RTX);
  2984.       break;
  2985.  
  2986.     case NOT:
  2987.       /* (not (plus X -1)) can become (neg X).  */
  2988.       if (GET_CODE (XEXP (x, 0)) == PLUS
  2989.       && XEXP (XEXP (x, 0), 1) == constm1_rtx)
  2990.     {
  2991.       x = gen_rtx_combine (NEG, mode, XEXP (XEXP (x, 0), 0));
  2992.       goto restart;
  2993.     }
  2994.  
  2995.       /* Similarly, (not (neg X)) is (plus X -1).  */
  2996.       if (GET_CODE (XEXP (x, 0)) == NEG)
  2997.     {
  2998.       x = gen_rtx_combine (PLUS, mode, XEXP (XEXP (x, 0), 0), constm1_rtx);
  2999.       goto restart;
  3000.     }
  3001.  
  3002.       /* (not (xor X C)) for C constant is (xor X D) with D = ~ C.  */
  3003.       if (GET_CODE (XEXP (x, 0)) == XOR
  3004.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  3005.       && (temp = simplify_unary_operation (NOT, mode,
  3006.                            XEXP (XEXP (x, 0), 1),
  3007.                            mode)) != 0)
  3008.     {
  3009.       SUBST (XEXP (XEXP (x, 0), 1), temp);
  3010.       return XEXP (x, 0);
  3011.     }
  3012.           
  3013.       /* (not (ashift 1 X)) is (rotate ~1 X).  We used to do this for operands
  3014.      other than 1, but that is not valid.  We could do a similar
  3015.      simplification for (not (lshiftrt C X)) where C is just the sign bit,
  3016.      but this doesn't seem common enough to bother with.  */
  3017.       if (GET_CODE (XEXP (x, 0)) == ASHIFT
  3018.       && XEXP (XEXP (x, 0), 0) == const1_rtx)
  3019.     {
  3020.       x = gen_rtx (ROTATE, mode, gen_unary (NOT, mode, const1_rtx),
  3021.                XEXP (XEXP (x, 0), 1));
  3022.       goto restart;
  3023.     }
  3024.                         
  3025.       if (GET_CODE (XEXP (x, 0)) == SUBREG
  3026.       && subreg_lowpart_p (XEXP (x, 0))
  3027.       && (GET_MODE_SIZE (GET_MODE (XEXP (x, 0)))
  3028.           < GET_MODE_SIZE (GET_MODE (SUBREG_REG (XEXP (x, 0)))))
  3029.       && GET_CODE (SUBREG_REG (XEXP (x, 0))) == ASHIFT
  3030.       && XEXP (SUBREG_REG (XEXP (x, 0)), 0) == const1_rtx)
  3031.     {
  3032.       enum machine_mode inner_mode = GET_MODE (SUBREG_REG (XEXP (x, 0)));
  3033.  
  3034.       x = gen_rtx (ROTATE, inner_mode,
  3035.                gen_unary (NOT, inner_mode, const1_rtx),
  3036.                XEXP (SUBREG_REG (XEXP (x, 0)), 1));
  3037.       x = gen_lowpart_for_combine (mode, x);
  3038.       goto restart;
  3039.     }
  3040.                         
  3041. #if STORE_FLAG_VALUE == -1
  3042.       /* (not (comparison foo bar)) can be done by reversing the comparison
  3043.      code if valid.  */
  3044.       if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
  3045.       && reversible_comparison_p (XEXP (x, 0)))
  3046.     return gen_rtx_combine (reverse_condition (GET_CODE (XEXP (x, 0))),
  3047.                 mode, XEXP (XEXP (x, 0), 0),
  3048.                 XEXP (XEXP (x, 0), 1));
  3049. #endif
  3050.  
  3051.       /* Apply De Morgan's laws to reduce number of patterns for machines
  3052.       with negating logical insns (and-not, nand, etc.).  If result has
  3053.       only one NOT, put it first, since that is how the patterns are
  3054.       coded.  */
  3055.  
  3056.       if (GET_CODE (XEXP (x, 0)) == IOR || GET_CODE (XEXP (x, 0)) == AND)
  3057.      {
  3058.       rtx in1 = XEXP (XEXP (x, 0), 0), in2 = XEXP (XEXP (x, 0), 1);
  3059.  
  3060.      if (GET_CODE (in1) == NOT)
  3061.        in1 = XEXP (in1, 0);
  3062.       else
  3063.        in1 = gen_rtx_combine (NOT, GET_MODE (in1), in1);
  3064.  
  3065.      if (GET_CODE (in2) == NOT)
  3066.        in2 = XEXP (in2, 0);
  3067.       else if (GET_CODE (in2) == CONST_INT
  3068.           && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
  3069.        in2 = GEN_INT (GET_MODE_MASK (mode) & ~ INTVAL (in2));
  3070.      else
  3071.        in2 = gen_rtx_combine (NOT, GET_MODE (in2), in2);
  3072.  
  3073.      if (GET_CODE (in2) == NOT)
  3074.        {
  3075.          rtx tem = in2;
  3076.          in2 = in1; in1 = tem;
  3077.        }
  3078.  
  3079.      x = gen_rtx_combine (GET_CODE (XEXP (x, 0)) == IOR ? AND : IOR,
  3080.                   mode, in1, in2);
  3081.      goto restart;
  3082.        } 
  3083.       break;
  3084.  
  3085.     case NEG:
  3086.       /* (neg (plus X 1)) can become (not X).  */
  3087.       if (GET_CODE (XEXP (x, 0)) == PLUS
  3088.       && XEXP (XEXP (x, 0), 1) == const1_rtx)
  3089.     {
  3090.       x = gen_rtx_combine (NOT, mode, XEXP (XEXP (x, 0), 0));
  3091.       goto restart;
  3092.     }
  3093.  
  3094.       /* Similarly, (neg (not X)) is (plus X 1).  */
  3095.       if (GET_CODE (XEXP (x, 0)) == NOT)
  3096.      {
  3097.       x = gen_rtx_combine (PLUS, mode, XEXP (XEXP (x, 0), 0), const1_rtx);
  3098.       goto restart;
  3099.      }
  3100.  
  3101.       /* (neg (minus X Y)) can become (minus Y X).  */
  3102.       if (GET_CODE (XEXP (x, 0)) == MINUS
  3103.       && (GET_MODE_CLASS (mode) != MODE_FLOAT
  3104.           /* x-y != -(y-x) with IEEE floating point. */
  3105.           || TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT))
  3106.     {
  3107.       x = gen_binary (MINUS, mode, XEXP (XEXP (x, 0), 1),
  3108.               XEXP (XEXP (x, 0), 0));
  3109.       goto restart;
  3110.     }
  3111.  
  3112.       /* (neg (xor A 1)) is (plus A -1) if A is known to be either 0 or 1. */
  3113.       if (GET_CODE (XEXP (x, 0)) == XOR && XEXP (XEXP (x, 0), 1) == const1_rtx
  3114.       && significant_bits (XEXP (XEXP (x, 0), 0), mode) == 1)
  3115.     {
  3116.       x = gen_binary (PLUS, mode, XEXP (XEXP (x, 0), 0), constm1_rtx);
  3117.       goto restart;
  3118.     }
  3119.  
  3120.       /* NEG commutes with ASHIFT since it is multiplication.  Only do this
  3121.      if we can then eliminate the NEG (e.g.,
  3122.      if the operand is a constant).  */
  3123.  
  3124.       if (GET_CODE (XEXP (x, 0)) == ASHIFT)
  3125.     {
  3126.       temp = simplify_unary_operation (NEG, mode,
  3127.                        XEXP (XEXP (x, 0), 0), mode);
  3128.       if (temp)
  3129.         {
  3130.           SUBST (XEXP (XEXP (x, 0), 0), temp);
  3131.           return XEXP (x, 0);
  3132.         }
  3133.     }
  3134.  
  3135.       temp = expand_compound_operation (XEXP (x, 0));
  3136.  
  3137.       /* For C equal to the width of MODE minus 1, (neg (ashiftrt X C)) can be
  3138.       replaced by (lshiftrt X C).  This will convert
  3139.      (neg (sign_extract X 1 Y)) to (zero_extract X 1 Y).  */
  3140.  
  3141.       if (GET_CODE (temp) == ASHIFTRT
  3142.       && GET_CODE (XEXP (temp, 1)) == CONST_INT
  3143.       && INTVAL (XEXP (temp, 1)) == GET_MODE_BITSIZE (mode) - 1)
  3144.     {
  3145.       x = simplify_shift_const (temp, LSHIFTRT, mode, XEXP (temp, 0),
  3146.                     INTVAL (XEXP (temp, 1)));
  3147.       goto restart;
  3148.     }
  3149.  
  3150.       /* If X has only a single bit significant, say, bit I, convert
  3151.      (neg X) to (ashiftrt (ashift X C-I) C-I) where C is the bitsize of
  3152.      MODE minus 1.  This will convert (neg (zero_extract X 1 Y)) to
  3153.      (sign_extract X 1 Y).  But only do this if TEMP isn't a register
  3154.      or a SUBREG of one since we'd be making the expression more
  3155.      complex if it was just a register.  */
  3156.  
  3157.       if (GET_CODE (temp) != REG
  3158.       && ! (GET_CODE (temp) == SUBREG
  3159.         && GET_CODE (SUBREG_REG (temp)) == REG)
  3160.       && (i = exact_log2 (significant_bits (temp, mode))) >= 0)
  3161.     {
  3162.       rtx temp1 = simplify_shift_const
  3163.         (NULL_RTX, ASHIFTRT, mode,
  3164.          simplify_shift_const (NULL_RTX, ASHIFT, mode, temp,
  3165.                    GET_MODE_BITSIZE (mode) - 1 - i),
  3166.          GET_MODE_BITSIZE (mode) - 1 - i);
  3167.  
  3168.       /* If all we did was surround TEMP with the two shifts, we
  3169.          haven't improved anything, so don't use it.  Otherwise,
  3170.          we are better off with TEMP1.  */
  3171.       if (GET_CODE (temp1) != ASHIFTRT
  3172.           || GET_CODE (XEXP (temp1, 0)) != ASHIFT
  3173.           || XEXP (XEXP (temp1, 0), 0) != temp)
  3174.         {
  3175.           x = temp1;
  3176.           goto restart;
  3177.         }
  3178.     }
  3179.       break;
  3180.  
  3181.     case FLOAT_TRUNCATE:
  3182.       /* (float_truncate:SF (float_extend:DF foo:SF)) = foo:SF.  */
  3183.       if (GET_CODE (XEXP (x, 0)) == FLOAT_EXTEND
  3184.       && GET_MODE (XEXP (XEXP (x, 0), 0)) == mode)
  3185.      return XEXP (XEXP (x, 0), 0);
  3186.       break;  
  3187.  
  3188. #ifdef HAVE_cc0
  3189.     case COMPARE:
  3190.       /* Convert (compare FOO (const_int 0)) to FOO unless we aren't
  3191.      using cc0, in which case we want to leave it as a COMPARE
  3192.      so we can distinguish it from a register-register-copy.  */
  3193.       if (XEXP (x, 1) == const0_rtx)
  3194.     return XEXP (x, 0);
  3195.  
  3196.       /* In IEEE floating point, x-0 is not the same as x.  */
  3197.       if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
  3198.        || GET_MODE_CLASS (GET_MODE (XEXP (x, 0))) == MODE_INT)
  3199.       && XEXP (x, 1) == CONST0_RTX (GET_MODE (XEXP (x, 0))))
  3200.     return XEXP (x, 0);
  3201.       break;
  3202. #endif
  3203.  
  3204.     case CONST:
  3205.       /* (const (const X)) can become (const X).  Do it this way rather than
  3206.      returning the inner CONST since CONST can be shared with a
  3207.      REG_EQUAL note.  */
  3208.       if (GET_CODE (XEXP (x, 0)) == CONST)
  3209.     SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  3210.       break;
  3211.  
  3212. #ifdef HAVE_lo_sum
  3213.     case LO_SUM:
  3214.       /* Convert (lo_sum (high FOO) FOO) to FOO.  This is necessary so we
  3215.      can add in an offset.  find_split_point will split this address up
  3216.      again if it doesn't match.  */
  3217.       if (GET_CODE (XEXP (x, 0)) == HIGH
  3218.       && rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (x, 1)))
  3219.     return XEXP (x, 1);
  3220.       break;
  3221. #endif
  3222.  
  3223.     case PLUS:
  3224.       /* If we have (plus (plus (A const) B)), associate it so that CONST is
  3225.      outermost.  That's because that's the way indexed addresses are
  3226.      supposed to appear.  This code used to check many more cases, but
  3227.      they are now checked elsewhere.  */
  3228.       if (GET_CODE (XEXP (x, 0)) == PLUS
  3229.       && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
  3230.     return gen_binary (PLUS, mode,
  3231.                gen_binary (PLUS, mode, XEXP (XEXP (x, 0), 0),
  3232.                        XEXP (x, 1)),
  3233.                XEXP (XEXP (x, 0), 1));
  3234.  
  3235.       /* (plus (xor (and <foo> (const_int pow2 - 1)) <c>) <-c>)
  3236.      when c is (const_int (pow2 + 1) / 2) is a sign extension of a
  3237.      bit-field and can be replaced by either a sign_extend or a
  3238.      sign_extract.  The `and' may be a zero_extend.  */
  3239.       if (GET_CODE (XEXP (x, 0)) == XOR
  3240.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  3241.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  3242.       && INTVAL (XEXP (x, 1)) == - INTVAL (XEXP (XEXP (x, 0), 1))
  3243.       && (i = exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)))) >= 0
  3244.       && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  3245.       && ((GET_CODE (XEXP (XEXP (x, 0), 0)) == AND
  3246.            && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
  3247.            && (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1))
  3248.            == ((HOST_WIDE_INT) 1 << (i + 1)) - 1))
  3249.           || (GET_CODE (XEXP (XEXP (x, 0), 0)) == ZERO_EXTEND
  3250.           && (GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (XEXP (x, 0), 0), 0)))
  3251.               == i + 1))))
  3252.     {
  3253.       x = simplify_shift_const
  3254.         (NULL_RTX, ASHIFTRT, mode,
  3255.          simplify_shift_const (NULL_RTX, ASHIFT, mode,
  3256.                    XEXP (XEXP (XEXP (x, 0), 0), 0),
  3257.                    GET_MODE_BITSIZE (mode) - (i + 1)),
  3258.          GET_MODE_BITSIZE (mode) - (i + 1));
  3259.       goto restart;
  3260.     }
  3261.  
  3262.       /* If only the low-order bit of X is significant, (plus x -1)
  3263.      can become (ashiftrt (ashift (xor x 1) C) C) where C is
  3264.      the bitsize of the mode - 1.  This allows simplification of
  3265.      "a = (b & 8) == 0;"  */
  3266.       if (XEXP (x, 1) == constm1_rtx
  3267.       && GET_CODE (XEXP (x, 0)) != REG
  3268.       && ! (GET_CODE (XEXP (x,0)) == SUBREG
  3269.         && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG)
  3270.       && significant_bits (XEXP (x, 0), mode) == 1)
  3271.     {
  3272.       x = simplify_shift_const
  3273.         (NULL_RTX, ASHIFTRT, mode,
  3274.          simplify_shift_const (NULL_RTX, ASHIFT, mode,
  3275.                    gen_rtx_combine (XOR, mode,
  3276.                             XEXP (x, 0), const1_rtx),
  3277.                    GET_MODE_BITSIZE (mode) - 1),
  3278.          GET_MODE_BITSIZE (mode) - 1);
  3279.       goto restart;
  3280.     }
  3281.  
  3282.       /* If we are adding two things that have no bits in common, convert
  3283.      the addition into an IOR.  This will often be further simplified,
  3284.      for example in cases like ((a & 1) + (a & 2)), which can
  3285.      become a & 3.  */
  3286.  
  3287.       if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  3288.       && (significant_bits (XEXP (x, 0), mode)
  3289.           & significant_bits (XEXP (x, 1), mode)) == 0)
  3290.     {
  3291.       x = gen_binary (IOR, mode, XEXP (x, 0), XEXP (x, 1));
  3292.       goto restart;
  3293.     }
  3294.       break;
  3295.  
  3296.     case MINUS:
  3297.       /* (minus <foo> (and <foo> (const_int -pow2))) becomes
  3298.      (and <foo> (const_int pow2-1))  */
  3299.       if (GET_CODE (XEXP (x, 1)) == AND
  3300.       && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
  3301.       && exact_log2 (- INTVAL (XEXP (XEXP (x, 1), 1))) >= 0
  3302.       && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0)))
  3303.     {
  3304.       x = simplify_and_const_int (NULL_RTX, mode, XEXP (x, 0),
  3305.                       - INTVAL (XEXP (XEXP (x, 1), 1)) - 1);
  3306.       goto restart;
  3307.     }
  3308.       break;
  3309.  
  3310.     case MULT:
  3311.       /* If we have (mult (plus A B) C), apply the distributive law and then
  3312.      the inverse distributive law to see if things simplify.  This
  3313.      occurs mostly in addresses, often when unrolling loops.  */
  3314.  
  3315.       if (GET_CODE (XEXP (x, 0)) == PLUS)
  3316.     {
  3317.       x = apply_distributive_law
  3318.         (gen_binary (PLUS, mode,
  3319.              gen_binary (MULT, mode,
  3320.                      XEXP (XEXP (x, 0), 0), XEXP (x, 1)),
  3321.              gen_binary (MULT, mode,
  3322.                      XEXP (XEXP (x, 0), 1), XEXP (x, 1))));
  3323.  
  3324.       if (GET_CODE (x) != MULT)
  3325.         goto restart;
  3326.     }
  3327.  
  3328.       /* If this is multiplication by a power of two and its first operand is
  3329.      a shift, treat the multiply as a shift to allow the shifts to
  3330.      possibly combine.  */
  3331.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  3332.       && (i = exact_log2 (INTVAL (XEXP (x, 1)))) >= 0
  3333.       && (GET_CODE (XEXP (x, 0)) == ASHIFT
  3334.           || GET_CODE (XEXP (x, 0)) == LSHIFTRT
  3335.           || GET_CODE (XEXP (x, 0)) == ASHIFTRT
  3336.           || GET_CODE (XEXP (x, 0)) == ROTATE
  3337.           || GET_CODE (XEXP (x, 0)) == ROTATERT))
  3338.     {
  3339.       x = simplify_shift_const (NULL_RTX, ASHIFT, mode, XEXP (x, 0), i);
  3340.       goto restart;
  3341.     }
  3342.  
  3343.       /* Convert (mult (ashift (const_int 1) A) B) to (ashift B A).  */
  3344.       if (GET_CODE (XEXP (x, 0)) == ASHIFT
  3345.       && XEXP (XEXP (x, 0), 0) == const1_rtx)
  3346.     return gen_rtx_combine (ASHIFT, mode, XEXP (x, 1),
  3347.                 XEXP (XEXP (x, 0), 1));
  3348.       break;
  3349.  
  3350.     case UDIV:
  3351.       /* If this is a divide by a power of two, treat it as a shift if
  3352.      its first operand is a shift.  */
  3353.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  3354.       && (i = exact_log2 (INTVAL (XEXP (x, 1)))) >= 0
  3355.       && (GET_CODE (XEXP (x, 0)) == ASHIFT
  3356.           || GET_CODE (XEXP (x, 0)) == LSHIFTRT
  3357.           || GET_CODE (XEXP (x, 0)) == ASHIFTRT
  3358.           || GET_CODE (XEXP (x, 0)) == ROTATE
  3359.           || GET_CODE (XEXP (x, 0)) == ROTATERT))
  3360.     {
  3361.       x = simplify_shift_const (NULL_RTX, LSHIFTRT, mode, XEXP (x, 0), i);
  3362.       goto restart;
  3363.     }
  3364.       break;
  3365.  
  3366.     case EQ:  case NE:
  3367.     case GT:  case GTU:  case GE:  case GEU:
  3368.     case LT:  case LTU:  case LE:  case LEU:
  3369.       /* If the first operand is a condition code, we can't do anything
  3370.      with it.  */
  3371.       if (GET_CODE (XEXP (x, 0)) == COMPARE
  3372.       || (GET_MODE_CLASS (GET_MODE (XEXP (x, 0))) != MODE_CC
  3373. #ifdef HAVE_cc0
  3374.           && XEXP (x, 0) != cc0_rtx
  3375. #endif
  3376.            ))
  3377.     {
  3378.       rtx op0 = XEXP (x, 0);
  3379.       rtx op1 = XEXP (x, 1);
  3380.       enum rtx_code new_code;
  3381.  
  3382.       if (GET_CODE (op0) == COMPARE)
  3383.         op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
  3384.  
  3385.       /* Simplify our comparison, if possible.  */
  3386.       new_code = simplify_comparison (code, &op0, &op1);
  3387.  
  3388. #if STORE_FLAG_VALUE == 1
  3389.       /* If STORE_FLAG_VALUE is 1, we can convert (ne x 0) to simply X
  3390.          if only the low-order bit is significant in X (such as when
  3391.          X is a ZERO_EXTRACT of one bit.  Similarly, we can convert
  3392.          EQ to (xor X 1).  */
  3393.       if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT
  3394.           && op1 == const0_rtx
  3395.           && significant_bits (op0, GET_MODE (op0)) == 1)
  3396.         return gen_lowpart_for_combine (mode, op0);
  3397.       else if (new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT
  3398.            && op1 == const0_rtx
  3399.            && significant_bits (op0, GET_MODE (op0)) == 1)
  3400.         return gen_rtx_combine (XOR, mode,
  3401.                     gen_lowpart_for_combine (mode, op0),
  3402.                     const1_rtx);
  3403. #endif
  3404.  
  3405. #if STORE_FLAG_VALUE == -1
  3406.       /* If STORE_FLAG_VALUE is -1, we can convert (ne x 0)
  3407.          to (neg x) if only the low-order bit of X is significant.
  3408.          This converts (ne (zero_extract X 1 Y) 0) to
  3409.          (sign_extract X 1 Y).  */
  3410.       if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT
  3411.           && op1 == const0_rtx
  3412.           && significant_bits (op0, GET_MODE (op0)) == 1)
  3413.         {
  3414.           x = gen_rtx_combine (NEG, mode,
  3415.                    gen_lowpart_for_combine (mode, op0));
  3416.           goto restart;
  3417.         }
  3418. #endif
  3419.  
  3420.       /* If STORE_FLAG_VALUE says to just test the sign bit and X has just
  3421.          one significant bit, we can convert (ne x 0) to (ashift x c)
  3422.          where C puts the bit in the sign bit.  Remove any AND with
  3423.          STORE_FLAG_VALUE when we are done, since we are only going to
  3424.          test the sign bit.  */
  3425.       if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT
  3426.           && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  3427.           && (STORE_FLAG_VALUE
  3428.           == (HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1))
  3429.           && op1 == const0_rtx
  3430.           && mode == GET_MODE (op0)
  3431.           && (i = exact_log2 (significant_bits (op0, GET_MODE (op0)))) >= 0)
  3432.         {
  3433.           x = simplify_shift_const (NULL_RTX, ASHIFT, mode, op0,
  3434.                     GET_MODE_BITSIZE (mode) - 1 - i);
  3435.           if (GET_CODE (x) == AND && XEXP (x, 1) == const_true_rtx)
  3436.         return XEXP (x, 0);
  3437.           else
  3438.         return x;
  3439.         }
  3440.  
  3441.       /* If the code changed, return a whole new comparison.  */
  3442.       if (new_code != code)
  3443.         return gen_rtx_combine (new_code, mode, op0, op1);
  3444.  
  3445.       /* Otherwise, keep this operation, but maybe change its operands.  
  3446.          This also converts (ne (compare FOO BAR) 0) to (ne FOO BAR).  */
  3447.       SUBST (XEXP (x, 0), op0);
  3448.       SUBST (XEXP (x, 1), op1);
  3449.     }
  3450.       break;
  3451.       
  3452.     case IF_THEN_ELSE:
  3453.       /* Sometimes we can simplify the arm of an IF_THEN_ELSE if a register
  3454.      used in it is being compared against certain values.  Get the
  3455.      true and false comparisons and see if that says anything about the
  3456.      value of each arm.  */
  3457.  
  3458.       if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
  3459.       && reversible_comparison_p (XEXP (x, 0))
  3460.       && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG)
  3461.     {
  3462.       HOST_WIDE_INT sig;
  3463.       rtx from = XEXP (XEXP (x, 0), 0);
  3464.       enum rtx_code true_code = GET_CODE (XEXP (x, 0));
  3465.       enum rtx_code false_code = reverse_condition (true_code);
  3466.       rtx true_val = XEXP (XEXP (x, 0), 1);
  3467.       rtx false_val = true_val;
  3468.       rtx true_arm = XEXP (x, 1);
  3469.       rtx false_arm = XEXP (x, 2);
  3470.       int swapped = 0;
  3471.  
  3472.       /* If FALSE_CODE is EQ, swap the codes and arms.  */
  3473.  
  3474.       if (false_code == EQ)
  3475.         {
  3476.           swapped = 1, true_code = EQ, false_code = NE;
  3477.           true_arm = XEXP (x, 2), false_arm = XEXP (x, 1);
  3478.         }
  3479.  
  3480.       /* If we are comparing against zero and the expression being tested
  3481.          has only a single significant bit, that is its value when it is 
  3482.          not equal to zero.  Similarly if it is known to be -1 or 0.  */
  3483.  
  3484.       if (true_code == EQ && true_val == const0_rtx
  3485.           && exact_log2 (sig = significant_bits (from,
  3486.                              GET_MODE (from))) >= 0)
  3487.         false_code = EQ, false_val = GEN_INT (sig);
  3488.       else if (true_code == EQ && true_val == const0_rtx
  3489.            && (num_sign_bit_copies (from, GET_MODE (from))
  3490.                == GET_MODE_BITSIZE (GET_MODE (from))))
  3491.         false_code = EQ, false_val = constm1_rtx;
  3492.  
  3493.       /* Now simplify an arm if we know the value of the register
  3494.          in the branch and it is used in the arm.  Be carefull due to
  3495.          the potential of locally-shared RTL.  */
  3496.  
  3497.       if (reg_mentioned_p (from, true_arm))
  3498.         true_arm = subst (known_cond (copy_rtx (true_arm), true_code,
  3499.                       from, true_val),
  3500.                   pc_rtx, pc_rtx, 0, 0);
  3501.       if (reg_mentioned_p (from, false_arm))
  3502.         false_arm = subst (known_cond (copy_rtx (false_arm), false_code,
  3503.                        from, false_val),
  3504.                    pc_rtx, pc_rtx, 0, 0);
  3505.  
  3506.       SUBST (XEXP (x, 1), swapped ? false_arm : true_arm);
  3507.       SUBST (XEXP (x, 2), swapped ? true_arm : false_arm);
  3508.     }
  3509.       
  3510.       /* If we have (if_then_else FOO (pc) (label_ref BAR)) and FOO can be
  3511.      reversed, do so to avoid needing two sets of patterns for
  3512.      subtract-and-branch insns.  Similarly if we have a constant in that
  3513.      position or if the third operand is the same as the first operand
  3514.      of the comparison.  */
  3515.  
  3516.       if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
  3517.       && reversible_comparison_p (XEXP (x, 0))
  3518.       && (XEXP (x, 1) == pc_rtx || GET_CODE (XEXP (x, 1)) == CONST_INT
  3519.           || rtx_equal_p (XEXP (x, 2), XEXP (XEXP (x, 0), 0))))
  3520.     {
  3521.       SUBST (XEXP (x, 0),
  3522.          gen_binary (reverse_condition (GET_CODE (XEXP (x, 0))),
  3523.                  GET_MODE (XEXP (x, 0)),
  3524.                  XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 0), 1)));
  3525.  
  3526.       temp = XEXP (x, 1);
  3527.       SUBST (XEXP (x, 1), XEXP (x, 2));
  3528.       SUBST (XEXP (x, 2), temp);
  3529.     }
  3530.  
  3531.       /* If the two arms are identical, we don't need the comparison.  */
  3532.  
  3533.       if (rtx_equal_p (XEXP (x, 1), XEXP (x, 2))
  3534.       && ! side_effects_p (XEXP (x, 0)))
  3535.     return XEXP (x, 1);
  3536.  
  3537.       /* Look for cases where we have (abs x) or (neg (abs X)).  */
  3538.  
  3539.       if (GET_MODE_CLASS (mode) == MODE_INT
  3540.       && GET_CODE (XEXP (x, 2)) == NEG
  3541.       && rtx_equal_p (XEXP (x, 1), XEXP (XEXP (x, 2), 0))
  3542.       && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
  3543.       && rtx_equal_p (XEXP (x, 1), XEXP (XEXP (x, 0), 0))
  3544.       && ! side_effects_p (XEXP (x, 1)))
  3545.     switch (GET_CODE (XEXP (x, 0)))
  3546.       {
  3547.       case GT:
  3548.       case GE:
  3549.         x = gen_unary (ABS, mode, XEXP (x, 1));
  3550.         goto restart;
  3551.       case LT:
  3552.       case LE:
  3553.         x = gen_unary (NEG, mode, gen_unary (ABS, mode, XEXP (x, 1)));
  3554.         goto restart;
  3555.       }
  3556.  
  3557.       /* Look for MIN or MAX.  */
  3558.  
  3559.       if (GET_MODE_CLASS (mode) == MODE_INT
  3560.       && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
  3561.       && rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (x, 1))
  3562.       && rtx_equal_p (XEXP (XEXP (x, 0), 1), XEXP (x, 2))
  3563.       && ! side_effects_p (XEXP (x, 0)))
  3564.     switch (GET_CODE (XEXP (x, 0)))
  3565.       {
  3566.       case GE:
  3567.       case GT:
  3568.         x = gen_binary (SMAX, mode, XEXP (x, 1), XEXP (x, 2));
  3569.         goto restart;
  3570.       case LE:
  3571.       case LT:
  3572.         x = gen_binary (SMIN, mode, XEXP (x, 1), XEXP (x, 2));
  3573.         goto restart;
  3574.       case GEU:
  3575.       case GTU:
  3576.         x = gen_binary (UMAX, mode, XEXP (x, 1), XEXP (x, 2));
  3577.         goto restart;
  3578.       case LEU:
  3579.       case LTU:
  3580.         x = gen_binary (UMIN, mode, XEXP (x, 1), XEXP (x, 2));
  3581.         goto restart;
  3582.       }
  3583.  
  3584.       /* If we have something like (if_then_else (ne A 0) (OP X C) X),
  3585.      A is known to be either 0 or 1, and OP is an identity when its
  3586.      second operand is zero, this can be done as (OP X (mult A C)).
  3587.      Similarly if A is known to be 0 or -1 and also similarly if we have
  3588.      a ZERO_EXTEND or SIGN_EXTEND as long as X is already extended (so
  3589.      we don't destroy it).  */
  3590.  
  3591.       if (mode != VOIDmode
  3592.       && (GET_CODE (XEXP (x, 0)) == EQ || GET_CODE (XEXP (x, 0)) == NE)
  3593.       && XEXP (XEXP (x, 0), 1) == const0_rtx
  3594.       && (significant_bits (XEXP (XEXP (x, 0), 0), mode) == 1
  3595.           || (num_sign_bit_copies (XEXP (XEXP (x, 0), 0), mode)
  3596.           == GET_MODE_BITSIZE (mode))))
  3597.     {
  3598.       rtx nz = make_compound_operation (GET_CODE (XEXP (x, 0)) == NE
  3599.                         ? XEXP (x, 1) : XEXP (x, 2));
  3600.       rtx z = GET_CODE (XEXP (x, 0)) == NE ? XEXP (x, 2) : XEXP (x, 1);
  3601.       rtx dir = (significant_bits (XEXP (XEXP (x, 0), 0), mode) == 1
  3602.              ? const1_rtx : constm1_rtx);
  3603.       rtx c = 0;
  3604.       enum machine_mode m = mode;
  3605.       enum rtx_code op, extend_op = 0;
  3606.  
  3607.       if ((GET_CODE (nz) == PLUS || GET_CODE (nz) == MINUS
  3608.            || GET_CODE (nz) == IOR || GET_CODE (nz) == XOR
  3609.            || GET_CODE (nz) == ASHIFT
  3610.            || GET_CODE (nz) == LSHIFTRT || GET_CODE (nz) == ASHIFTRT)
  3611.           && rtx_equal_p (XEXP (nz, 0), z))
  3612.         c = XEXP (nz, 1), op = GET_CODE (nz);
  3613.       else if (GET_CODE (nz) == SIGN_EXTEND
  3614.            && (GET_CODE (XEXP (nz, 0)) == PLUS
  3615.                || GET_CODE (XEXP (nz, 0)) == MINUS
  3616.                || GET_CODE (XEXP (nz, 0)) == IOR
  3617.                || GET_CODE (XEXP (nz, 0)) == XOR
  3618.                || GET_CODE (XEXP (nz, 0)) == ASHIFT
  3619.                || GET_CODE (XEXP (nz, 0)) == LSHIFTRT
  3620.                || GET_CODE (XEXP (nz, 0)) == ASHIFTRT)
  3621.            && GET_CODE (XEXP (XEXP (nz, 0), 0)) == SUBREG
  3622.            && subreg_lowpart_p (XEXP (XEXP (nz, 0), 0))
  3623.            && rtx_equal_p (SUBREG_REG (XEXP (XEXP (nz, 0), 0)), z)
  3624.            && (num_sign_bit_copies (z, GET_MODE (z))
  3625.                >= (GET_MODE_BITSIZE (mode)
  3626.                - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (nz, 0), 0))))))
  3627.         {
  3628.           c = XEXP (XEXP (nz, 0), 1);
  3629.           op = GET_CODE (XEXP (nz, 0));
  3630.           extend_op = SIGN_EXTEND;
  3631.           m = GET_MODE (XEXP (nz, 0));
  3632.         }
  3633.       else if (GET_CODE (nz) == ZERO_EXTEND
  3634.            && (GET_CODE (XEXP (nz, 0)) == PLUS
  3635.                || GET_CODE (XEXP (nz, 0)) == MINUS
  3636.                || GET_CODE (XEXP (nz, 0)) == IOR
  3637.                || GET_CODE (XEXP (nz, 0)) == XOR
  3638.                || GET_CODE (XEXP (nz, 0)) == ASHIFT
  3639.                || GET_CODE (XEXP (nz, 0)) == LSHIFTRT
  3640.                || GET_CODE (XEXP (nz, 0)) == ASHIFTRT)
  3641.            && GET_CODE (XEXP (XEXP (nz, 0), 0)) == SUBREG
  3642.            && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  3643.            && subreg_lowpart_p (XEXP (XEXP (nz, 0), 0))
  3644.            && rtx_equal_p (SUBREG_REG (XEXP (XEXP (nz, 0), 0)), z)
  3645.            && ((significant_bits (z, GET_MODE (z))
  3646.             & ~ GET_MODE_MASK (GET_MODE (XEXP (XEXP (nz, 0), 0))))
  3647.                == 0))
  3648.         {
  3649.           c = XEXP (XEXP (nz, 0), 1);
  3650.           op = GET_CODE (XEXP (nz, 0));
  3651.           extend_op = ZERO_EXTEND;
  3652.           m = GET_MODE (XEXP (nz, 0));
  3653.         }
  3654.  
  3655.       if (c && ! side_effects_p (c) && ! side_effects_p (z))
  3656.         {
  3657.           temp
  3658.         = gen_binary (MULT, m,
  3659.                   gen_lowpart_for_combine (m,
  3660.                                XEXP (XEXP (x, 0), 0)),
  3661.                   gen_binary (MULT, m, c, dir));
  3662.  
  3663.           temp = gen_binary (op, m, gen_lowpart_for_combine (m, z), temp);
  3664.  
  3665.           if (extend_op != 0)
  3666.         temp = gen_unary (extend_op, mode, temp);
  3667.  
  3668.           return temp;
  3669.         }
  3670.     }
  3671.       break;
  3672.       
  3673.     case ZERO_EXTRACT:
  3674.     case SIGN_EXTRACT:
  3675.     case ZERO_EXTEND:
  3676.     case SIGN_EXTEND:
  3677.       /* If we are processing SET_DEST, we are done. */
  3678.       if (in_dest)
  3679.     return x;
  3680.  
  3681.       x = expand_compound_operation (x);
  3682.       if (GET_CODE (x) != code)
  3683.     goto restart;
  3684.       break;
  3685.  
  3686.     case SET:
  3687.       /* (set (pc) (return)) gets written as (return).  */
  3688.       if (GET_CODE (SET_DEST (x)) == PC && GET_CODE (SET_SRC (x)) == RETURN)
  3689.     return SET_SRC (x);
  3690.  
  3691.       /* Convert this into a field assignment operation, if possible.  */
  3692.       x = make_field_assignment (x);
  3693.  
  3694.       /* If we are setting CC0 or if the source is a COMPARE, look for the
  3695.      use of the comparison result and try to simplify it unless we already
  3696.      have used undobuf.other_insn.  */
  3697.       if ((GET_CODE (SET_SRC (x)) == COMPARE
  3698. #ifdef HAVE_cc0
  3699.        || SET_DEST (x) == cc0_rtx
  3700. #endif
  3701.        )
  3702.       && (cc_use = find_single_use (SET_DEST (x), subst_insn,
  3703.                     &other_insn)) != 0
  3704.       && (undobuf.other_insn == 0 || other_insn == undobuf.other_insn)
  3705.       && GET_RTX_CLASS (GET_CODE (*cc_use)) == '<'
  3706.       && XEXP (*cc_use, 0) == SET_DEST (x))
  3707.     {
  3708.       enum rtx_code old_code = GET_CODE (*cc_use);
  3709.       enum rtx_code new_code;
  3710.       rtx op0, op1;
  3711.       int other_changed = 0;
  3712.       enum machine_mode compare_mode = GET_MODE (SET_DEST (x));
  3713.  
  3714.       if (GET_CODE (SET_SRC (x)) == COMPARE)
  3715.         op0 = XEXP (SET_SRC (x), 0), op1 = XEXP (SET_SRC (x), 1);
  3716.       else
  3717.         op0 = SET_SRC (x), op1 = const0_rtx;
  3718.  
  3719.       /* Simplify our comparison, if possible.  */
  3720.       new_code = simplify_comparison (old_code, &op0, &op1);
  3721.  
  3722. #if !defined (HAVE_cc0) && defined (EXTRA_CC_MODES)
  3723.       /* If this machine has CC modes other than CCmode, check to see
  3724.          if we need to use a different CC mode here.  */
  3725.       compare_mode = SELECT_CC_MODE (new_code, op0, op1);
  3726.  
  3727.       /* If the mode changed, we have to change SET_DEST, the mode
  3728.          in the compare, and the mode in the place SET_DEST is used.
  3729.          If SET_DEST is a hard register, just build new versions with
  3730.          the proper mode.  If it is a pseudo, we lose unless it is only
  3731.          time we set the pseudo, in which case we can safely change
  3732.          its mode.  */
  3733.       if (compare_mode != GET_MODE (SET_DEST (x)))
  3734.         {
  3735.           int regno = REGNO (SET_DEST (x));
  3736.           rtx new_dest = gen_rtx (REG, compare_mode, regno);
  3737.  
  3738.           if (regno < FIRST_PSEUDO_REGISTER
  3739.           || (reg_n_sets[regno] == 1
  3740.               && ! REG_USERVAR_P (SET_DEST (x))))
  3741.         {
  3742.           if (regno >= FIRST_PSEUDO_REGISTER)
  3743.             SUBST (regno_reg_rtx[regno], new_dest);
  3744.  
  3745.           SUBST (SET_DEST (x), new_dest);
  3746.           SUBST (XEXP (*cc_use, 0), new_dest);
  3747.           other_changed = 1;
  3748.         }
  3749.         }
  3750. #endif
  3751.  
  3752.       /* If the code changed, we have to build a new comparison
  3753.          in undobuf.other_insn.  */
  3754.       if (new_code != old_code)
  3755.         {
  3756.           unsigned mask;
  3757.  
  3758.           SUBST (*cc_use, gen_rtx_combine (new_code, GET_MODE (*cc_use),
  3759.                            SET_DEST (x), const0_rtx));
  3760.  
  3761.           /* If the only change we made was to change an EQ into an
  3762.          NE or vice versa, OP0 has only one significant bit,
  3763.          and OP1 is zero, check if changing the user of the condition
  3764.          code will produce a valid insn.  If it won't, we can keep
  3765.          the original code in that insn by surrounding our operation
  3766.          with an XOR.  */
  3767.  
  3768.           if (((old_code == NE && new_code == EQ)
  3769.            || (old_code == EQ && new_code == NE))
  3770.           && ! other_changed && op1 == const0_rtx
  3771.           && (GET_MODE_BITSIZE (GET_MODE (op0))
  3772.               <= HOST_BITS_PER_WIDE_INT)
  3773.           && (exact_log2 (mask = significant_bits (op0,
  3774.                                GET_MODE (op0)))
  3775.               >= 0))
  3776.         {
  3777.           rtx pat = PATTERN (other_insn), note = 0;
  3778.  
  3779.           if ((recog_for_combine (&pat, undobuf.other_insn, ¬e) < 0
  3780.                && ! check_asm_operands (pat)))
  3781.             {
  3782.               PUT_CODE (*cc_use, old_code);
  3783.               other_insn = 0;
  3784.  
  3785.               op0 = gen_binary (XOR, GET_MODE (op0), op0,
  3786.                     GEN_INT (mask));
  3787.             }
  3788.         }
  3789.  
  3790.           other_changed = 1;
  3791.         }
  3792.  
  3793.       if (other_changed)
  3794.         undobuf.other_insn = other_insn;
  3795.  
  3796. #ifdef HAVE_cc0
  3797.       /* If we are now comparing against zero, change our source if
  3798.          needed.  If we do not use cc0, we always have a COMPARE.  */
  3799.       if (op1 == const0_rtx && SET_DEST (x) == cc0_rtx)
  3800.         SUBST (SET_SRC (x), op0);
  3801.       else
  3802. #endif
  3803.  
  3804.       /* Otherwise, if we didn't previously have a COMPARE in the
  3805.          correct mode, we need one.  */
  3806.       if (GET_CODE (SET_SRC (x)) != COMPARE
  3807.           || GET_MODE (SET_SRC (x)) != compare_mode)
  3808.         SUBST (SET_SRC (x), gen_rtx_combine (COMPARE, compare_mode,
  3809.                          op0, op1));
  3810.       else
  3811.         {
  3812.           /* Otherwise, update the COMPARE if needed.  */
  3813.           SUBST (XEXP (SET_SRC (x), 0), op0);
  3814.           SUBST (XEXP (SET_SRC (x), 1), op1);
  3815.         }
  3816.     }
  3817.       else
  3818.     {
  3819.       /* Get SET_SRC in a form where we have placed back any
  3820.          compound expressions.  Then do the checks below.  */
  3821.       temp = make_compound_operation (SET_SRC (x), SET);
  3822.       SUBST (SET_SRC (x), temp);
  3823.     }
  3824.  
  3825.       /* If we have (set x (subreg:m1 (op:m2 ...) 0)) with OP being some
  3826.      operation, and X being a REG or (subreg (reg)), we may be able to
  3827.      convert this to (set (subreg:m2 x) (op)).
  3828.  
  3829.      We can always do this if M1 is narrower than M2 because that
  3830.      means that we only care about the low bits of the result.
  3831.  
  3832.      However, on most machines (those with BYTE_LOADS_ZERO_EXTEND
  3833.      and BYTES_LOADS_SIGN_EXTEND not defined), we cannot perform a
  3834.      narrower operation that requested since the high-order bits will
  3835.      be undefined.  On machine where BYTE_LOADS_*_EXTEND is defined,
  3836.      however, this transformation is safe as long as M1 and M2 have
  3837.      the same number of words.  */
  3838.  
  3839.       if (GET_CODE (SET_SRC (x)) == SUBREG
  3840.       && subreg_lowpart_p (SET_SRC (x))
  3841.       && GET_RTX_CLASS (GET_CODE (SUBREG_REG (SET_SRC (x)))) != 'o'
  3842.       && (((GET_MODE_SIZE (GET_MODE (SET_SRC (x))) + (UNITS_PER_WORD - 1))
  3843.            / UNITS_PER_WORD)
  3844.           == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_SRC (x))))
  3845.            + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))
  3846. #if ! defined(BYTE_LOADS_ZERO_EXTEND) && ! defined (BYTE_LOADS_SIGN_EXTEND)
  3847.       && (GET_MODE_SIZE (GET_MODE (SET_SRC (x)))
  3848.           < GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_SRC (x)))))
  3849. #endif
  3850.       && (GET_CODE (SET_DEST (x)) == REG
  3851.           || (GET_CODE (SET_DEST (x)) == SUBREG
  3852.           && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG)))
  3853.     {
  3854.       SUBST (SET_DEST (x),
  3855.          gen_lowpart_for_combine (GET_MODE (SUBREG_REG (SET_SRC (x))),
  3856.                       SET_DEST (x)));
  3857.       SUBST (SET_SRC (x), SUBREG_REG (SET_SRC (x)));
  3858.     }
  3859.  
  3860. #ifdef BYTE_LOADS_ZERO_EXTEND
  3861.       /* If we have (set FOO (subreg:M (mem:N BAR) 0)) with
  3862.      M wider than N, this would require a paradoxical subreg.
  3863.      Replace the subreg with a zero_extend to avoid the reload that
  3864.      would otherwise be required. */
  3865.       if (GET_CODE (SET_SRC (x)) == SUBREG
  3866.       && subreg_lowpart_p (SET_SRC (x))
  3867.       && SUBREG_WORD (SET_SRC (x)) == 0
  3868.       && (GET_MODE_SIZE (GET_MODE (SET_SRC (x)))
  3869.           > GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_SRC (x)))))
  3870.       && GET_CODE (SUBREG_REG (SET_SRC (x))) == MEM)
  3871.     SUBST (SET_SRC (x), gen_rtx_combine (ZERO_EXTEND,
  3872.                          GET_MODE (SET_SRC (x)),
  3873.                          XEXP (SET_SRC (x), 0)));
  3874. #endif
  3875.  
  3876. #ifndef HAVE_conditional_move
  3877.  
  3878.       /* If we don't have a conditional move, SET_SRC is an IF_THEN_ELSE,
  3879.      and we are comparing an item known to be 0 or -1 against 0, use a
  3880.      logical operation instead. Check for one of the arms being an IOR
  3881.      of the other arm with some value.  We compute three terms to be
  3882.      IOR'ed together.  In practice, at most two will be nonzero.  Then
  3883.      we do the IOR's.  */
  3884.  
  3885.       if (GET_CODE (SET_DEST (x)) != PC
  3886.       && GET_CODE (SET_SRC (x)) == IF_THEN_ELSE
  3887.       && (GET_CODE (XEXP (SET_SRC (x), 0)) == EQ
  3888.           || GET_CODE (XEXP (SET_SRC (x), 0)) == NE)
  3889.       && XEXP (XEXP (SET_SRC (x), 0), 1) == const0_rtx
  3890.       && (num_sign_bit_copies (XEXP (XEXP (SET_SRC (x), 0), 0),
  3891.                    GET_MODE (XEXP (XEXP (SET_SRC (x), 0), 0)))
  3892.           == GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (SET_SRC (x), 0), 0))))
  3893.       && ! side_effects_p (SET_SRC (x)))
  3894.     {
  3895.       rtx true = (GET_CODE (XEXP (SET_SRC (x), 0)) == NE
  3896.               ? XEXP (SET_SRC (x), 1) : XEXP (SET_SRC (x), 2));
  3897.       rtx false = (GET_CODE (XEXP (SET_SRC (x), 0)) == NE
  3898.                ? XEXP (SET_SRC (x), 2) : XEXP (SET_SRC (x), 1));
  3899.       rtx term1 = const0_rtx, term2, term3;
  3900.  
  3901.       if (GET_CODE (true) == IOR && rtx_equal_p (XEXP (true, 0), false))
  3902.         term1 = false, true = XEXP (true, 1), false = const0_rtx;
  3903.       else if (GET_CODE (true) == IOR
  3904.            && rtx_equal_p (XEXP (true, 1), false))
  3905.         term1 = false, true = XEXP (true, 0), false = const0_rtx;
  3906.       else if (GET_CODE (false) == IOR
  3907.            && rtx_equal_p (XEXP (false, 0), true))
  3908.         term1 = true, false = XEXP (false, 1), true = const0_rtx;
  3909.       else if (GET_CODE (false) == IOR
  3910.            && rtx_equal_p (XEXP (false, 1), true))
  3911.         term1 = true, false = XEXP (false, 0), true = const0_rtx;
  3912.  
  3913.       term2 = gen_binary (AND, GET_MODE (SET_SRC (x)),
  3914.                   XEXP (XEXP (SET_SRC (x), 0), 0), true);
  3915.       term3 = gen_binary (AND, GET_MODE (SET_SRC (x)),
  3916.                   gen_unary (NOT, GET_MODE (SET_SRC (x)),
  3917.                      XEXP (XEXP (SET_SRC (x), 0), 0)),
  3918.                   false);
  3919.  
  3920.       SUBST (SET_SRC (x),
  3921.          gen_binary (IOR, GET_MODE (SET_SRC (x)),
  3922.                  gen_binary (IOR, GET_MODE (SET_SRC (x)),
  3923.                      term1, term2),
  3924.                  term3));
  3925.     }
  3926. #endif
  3927.       break;
  3928.  
  3929.     case AND:
  3930.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  3931.     {
  3932.       x = simplify_and_const_int (x, mode, XEXP (x, 0),
  3933.                       INTVAL (XEXP (x, 1)));
  3934.  
  3935.       /* If we have (ior (and (X C1) C2)) and the next restart would be
  3936.          the last, simplify this by making C1 as small as possible
  3937.          and then exit. */
  3938.       if (n_restarts >= 3 && GET_CODE (x) == IOR
  3939.           && GET_CODE (XEXP (x, 0)) == AND
  3940.           && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  3941.           && GET_CODE (XEXP (x, 1)) == CONST_INT)
  3942.         {
  3943.           temp = gen_binary (AND, mode, XEXP (XEXP (x, 0), 0),
  3944.                  GEN_INT (INTVAL (XEXP (XEXP (x, 0), 1))
  3945.                       & ~ INTVAL (XEXP (x, 1))));
  3946.           return gen_binary (IOR, mode, temp, XEXP (x, 1));
  3947.         }
  3948.  
  3949.       if (GET_CODE (x) != AND)
  3950.         goto restart;
  3951.     }
  3952.  
  3953.       /* Convert (A | B) & A to A.  */
  3954.       if (GET_CODE (XEXP (x, 0)) == IOR
  3955.       && (rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (x, 1))
  3956.           || rtx_equal_p (XEXP (XEXP (x, 0), 1), XEXP (x, 1)))
  3957.       && ! side_effects_p (XEXP (XEXP (x, 0), 0))
  3958.       && ! side_effects_p (XEXP (XEXP (x, 0), 1)))
  3959.     return XEXP (x, 1);
  3960.  
  3961.       /* Convert (A ^ B) & A to A & (~ B) since the latter is often a single
  3962.      insn (and may simplify more).  */
  3963.       else if (GET_CODE (XEXP (x, 0)) == XOR
  3964.       && rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (x, 1))
  3965.       && ! side_effects_p (XEXP (x, 1)))
  3966.     {
  3967.       x = gen_binary (AND, mode,
  3968.               gen_unary (NOT, mode, XEXP (XEXP (x, 0), 1)),
  3969.               XEXP (x, 1));
  3970.       goto restart;
  3971.     }
  3972.       else if (GET_CODE (XEXP (x, 0)) == XOR
  3973.            && rtx_equal_p (XEXP (XEXP (x, 0), 1), XEXP (x, 1))
  3974.            && ! side_effects_p (XEXP (x, 1)))
  3975.     {
  3976.       x = gen_binary (AND, mode,
  3977.               gen_unary (NOT, mode, XEXP (XEXP (x, 0), 0)),
  3978.               XEXP (x, 1));
  3979.       goto restart;
  3980.     }
  3981.  
  3982.       /* Similarly for (~ (A ^ B)) & A.  */
  3983.       else if (GET_CODE (XEXP (x, 0)) == NOT
  3984.            && GET_CODE (XEXP (XEXP (x, 0), 0)) == XOR
  3985.            && rtx_equal_p (XEXP (XEXP (XEXP (x, 0), 0), 0), XEXP (x, 1))
  3986.            && ! side_effects_p (XEXP (x, 1)))
  3987.     {
  3988.       x = gen_binary (AND, mode, XEXP (XEXP (XEXP (x, 0), 0), 1),
  3989.               XEXP (x, 1));
  3990.       goto restart;
  3991.     }
  3992.       else if (GET_CODE (XEXP (x, 0)) == NOT
  3993.            && GET_CODE (XEXP (XEXP (x, 0), 0)) == XOR
  3994.            && rtx_equal_p (XEXP (XEXP (XEXP (x, 0), 0), 1), XEXP (x, 1))
  3995.            && ! side_effects_p (XEXP (x, 1)))
  3996.     {
  3997.       x = gen_binary (AND, mode, XEXP (XEXP (XEXP (x, 0), 0), 0),
  3998.               XEXP (x, 1));
  3999.       goto restart;
  4000.     }
  4001.  
  4002.       /* If we have (and A B) with A not an object but that is known to
  4003.      be -1 or 0, this is equivalent to the expression
  4004.      (if_then_else (ne A (const_int 0)) B (const_int 0))
  4005.      We make this conversion because it may allow further
  4006.      simplifications and then allow use of conditional move insns.
  4007.      If the machine doesn't have condition moves, code in case SET
  4008.      will convert the IF_THEN_ELSE back to the logical operation.
  4009.      We build the IF_THEN_ELSE here in case further simplification
  4010.      is possible (e.g., we can convert it to ABS).  */
  4011.  
  4012.       if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) != 'o'
  4013.       && ! (GET_CODE (XEXP (x, 0)) == SUBREG
  4014.         && GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0)))) == 'o')
  4015.       && (num_sign_bit_copies (XEXP (x, 0), GET_MODE (XEXP (x, 0)))
  4016.           == GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))))
  4017.     {
  4018.       rtx op0 = XEXP (x, 0);
  4019.       rtx op1 = const0_rtx;
  4020.       enum rtx_code comp_code
  4021.         = simplify_comparison (NE, &op0, &op1);
  4022.  
  4023.       x =  gen_rtx_combine (IF_THEN_ELSE, mode,
  4024.                 gen_binary (comp_code, VOIDmode, op0, op1),
  4025.                 XEXP (x, 1), const0_rtx);
  4026.       goto restart;
  4027.     }
  4028.  
  4029.       /* In the following group of tests (and those in case IOR below),
  4030.      we start with some combination of logical operations and apply
  4031.      the distributive law followed by the inverse distributive law.
  4032.      Most of the time, this results in no change.  However, if some of
  4033.      the operands are the same or inverses of each other, simplifications
  4034.      will result.
  4035.  
  4036.      For example, (and (ior A B) (not B)) can occur as the result of
  4037.      expanding a bit field assignment.  When we apply the distributive
  4038.      law to this, we get (ior (and (A (not B))) (and (B (not B)))),
  4039.      which then simplifies to (and (A (not B))).  */
  4040.  
  4041.       /* If we have (and (ior A B) C), apply the distributive law and then
  4042.      the inverse distributive law to see if things simplify.  */
  4043.  
  4044.       if (GET_CODE (XEXP (x, 0)) == IOR || GET_CODE (XEXP (x, 0)) == XOR)
  4045.     {
  4046.       x = apply_distributive_law
  4047.         (gen_binary (GET_CODE (XEXP (x, 0)), mode,
  4048.              gen_binary (AND, mode,
  4049.                      XEXP (XEXP (x, 0), 0), XEXP (x, 1)),
  4050.              gen_binary (AND, mode,
  4051.                      XEXP (XEXP (x, 0), 1), XEXP (x, 1))));
  4052.       if (GET_CODE (x) != AND)
  4053.         goto restart;
  4054.     }
  4055.  
  4056.       if (GET_CODE (XEXP (x, 1)) == IOR || GET_CODE (XEXP (x, 1)) == XOR)
  4057.     {
  4058.       x = apply_distributive_law
  4059.         (gen_binary (GET_CODE (XEXP (x, 1)), mode,
  4060.              gen_binary (AND, mode,
  4061.                      XEXP (XEXP (x, 1), 0), XEXP (x, 0)),
  4062.              gen_binary (AND, mode,
  4063.                      XEXP (XEXP (x, 1), 1), XEXP (x, 0))));
  4064.       if (GET_CODE (x) != AND)
  4065.         goto restart;
  4066.     }
  4067.  
  4068.       /* Similarly, taking advantage of the fact that
  4069.      (and (not A) (xor B C)) == (xor (ior A B) (ior A C))  */
  4070.  
  4071.       if (GET_CODE (XEXP (x, 0)) == NOT && GET_CODE (XEXP (x, 1)) == XOR)
  4072.     {
  4073.       x = apply_distributive_law
  4074.         (gen_binary (XOR, mode,
  4075.              gen_binary (IOR, mode, XEXP (XEXP (x, 0), 0),
  4076.                      XEXP (XEXP (x, 1), 0)),
  4077.              gen_binary (IOR, mode, XEXP (XEXP (x, 0), 0),
  4078.                      XEXP (XEXP (x, 1), 1))));
  4079.       if (GET_CODE (x) != AND)
  4080.         goto restart;
  4081.     }
  4082.                                 
  4083.       else if (GET_CODE (XEXP (x, 1)) == NOT && GET_CODE (XEXP (x, 0)) == XOR)
  4084.     {
  4085.       x = apply_distributive_law
  4086.         (gen_binary (XOR, mode,
  4087.              gen_binary (IOR, mode, XEXP (XEXP (x, 1), 0),
  4088.                      XEXP (XEXP (x, 0), 0)),
  4089.              gen_binary (IOR, mode, XEXP (XEXP (x, 1), 0),
  4090.                      XEXP (XEXP (x, 0), 1))));
  4091.       if (GET_CODE (x) != AND)
  4092.         goto restart;
  4093.     }
  4094.       break;
  4095.  
  4096.     case IOR:
  4097.       /* (ior A C) is C if all significant bits of A are on in C.  */
  4098.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  4099.       && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  4100.       && (significant_bits (XEXP (x, 0), mode)
  4101.           & ~ INTVAL (XEXP (x, 1))) == 0)
  4102.     return XEXP (x, 1);
  4103.  
  4104.       /* Convert (A & B) | A to A.  */
  4105.       if (GET_CODE (XEXP (x, 0)) == AND
  4106.       && (rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (x, 1))
  4107.           || rtx_equal_p (XEXP (XEXP (x, 0), 1), XEXP (x, 1)))
  4108.       && ! side_effects_p (XEXP (XEXP (x, 0), 0))
  4109.       && ! side_effects_p (XEXP (XEXP (x, 0), 1)))
  4110.     return XEXP (x, 1);
  4111.  
  4112.       /* If we have (ior (and A B) C), apply the distributive law and then
  4113.      the inverse distributive law to see if things simplify.  */
  4114.  
  4115.       if (GET_CODE (XEXP (x, 0)) == AND)
  4116.     {
  4117.       x = apply_distributive_law
  4118.         (gen_binary (AND, mode,
  4119.              gen_binary (IOR, mode,
  4120.                      XEXP (XEXP (x, 0), 0), XEXP (x, 1)),
  4121.              gen_binary (IOR, mode,
  4122.                      XEXP (XEXP (x, 0), 1), XEXP (x, 1))));
  4123.  
  4124.       if (GET_CODE (x) != IOR)
  4125.         goto restart;
  4126.     }
  4127.  
  4128.       if (GET_CODE (XEXP (x, 1)) == AND)
  4129.     {
  4130.       x = apply_distributive_law
  4131.         (gen_binary (AND, mode,
  4132.              gen_binary (IOR, mode,
  4133.                      XEXP (XEXP (x, 1), 0), XEXP (x, 0)),
  4134.              gen_binary (IOR, mode,
  4135.                      XEXP (XEXP (x, 1), 1), XEXP (x, 0))));
  4136.  
  4137.       if (GET_CODE (x) != IOR)
  4138.         goto restart;
  4139.     }
  4140.  
  4141.       /* Convert (ior (ashift A CX) (lshiftrt A CY)) where CX+CY equals the
  4142.      mode size to (rotate A CX).  */
  4143.  
  4144.       if (((GET_CODE (XEXP (x, 0)) == ASHIFT
  4145.         && GET_CODE (XEXP (x, 1)) == LSHIFTRT)
  4146.        || (GET_CODE (XEXP (x, 1)) == ASHIFT
  4147.            && GET_CODE (XEXP (x, 0)) == LSHIFTRT))
  4148.       && rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 1), 0))
  4149.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  4150.       && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
  4151.       && (INTVAL (XEXP (XEXP (x, 0), 1)) + INTVAL (XEXP (XEXP (x, 1), 1))
  4152.           == GET_MODE_BITSIZE (mode)))
  4153.     {
  4154.       rtx shift_count;
  4155.  
  4156.       if (GET_CODE (XEXP (x, 0)) == ASHIFT)
  4157.         shift_count = XEXP (XEXP (x, 0), 1);
  4158.       else
  4159.         shift_count = XEXP (XEXP (x, 1), 1);
  4160.       x = gen_rtx (ROTATE, mode, XEXP (XEXP (x, 0), 0), shift_count);
  4161.       goto restart;
  4162.     }
  4163.       break;
  4164.  
  4165.     case XOR:
  4166.       /* Convert (XOR (NOT x) (NOT y)) to (XOR x y).
  4167.      Also convert (XOR (NOT x) y) to (NOT (XOR x y)), similarly for
  4168.      (NOT y).  */
  4169.       {
  4170.     int num_negated = 0;
  4171.     rtx in1 = XEXP (x, 0), in2 = XEXP (x, 1);
  4172.  
  4173.     if (GET_CODE (in1) == NOT)
  4174.       num_negated++, in1 = XEXP (in1, 0);
  4175.     if (GET_CODE (in2) == NOT)
  4176.       num_negated++, in2 = XEXP (in2, 0);
  4177.  
  4178.     if (num_negated == 2)
  4179.       {
  4180.         SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  4181.         SUBST (XEXP (x, 1), XEXP (XEXP (x, 1), 0));
  4182.       }
  4183.     else if (num_negated == 1)
  4184.       {
  4185.         x =  gen_unary (NOT, mode,
  4186.                 gen_binary (XOR, mode, in1, in2));
  4187.         goto restart;
  4188.       }
  4189.       }
  4190.  
  4191.       /* Convert (xor (and A B) B) to (and (not A) B).  The latter may
  4192.      correspond to a machine insn or result in further simplifications
  4193.      if B is a constant.  */
  4194.  
  4195.       if (GET_CODE (XEXP (x, 0)) == AND
  4196.       && rtx_equal_p (XEXP (XEXP (x, 0), 1), XEXP (x, 1))
  4197.       && ! side_effects_p (XEXP (x, 1)))
  4198.     {
  4199.       x = gen_binary (AND, mode,
  4200.               gen_unary (NOT, mode, XEXP (XEXP (x, 0), 0)),
  4201.               XEXP (x, 1));
  4202.       goto restart;
  4203.     }
  4204.       else if (GET_CODE (XEXP (x, 0)) == AND
  4205.            && rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (x, 1))
  4206.            && ! side_effects_p (XEXP (x, 1)))
  4207.     {
  4208.       x = gen_binary (AND, mode,
  4209.               gen_unary (NOT, mode, XEXP (XEXP (x, 0), 1)),
  4210.               XEXP (x, 1));
  4211.       goto restart;
  4212.     }
  4213.  
  4214.  
  4215. #if STORE_FLAG_VALUE == 1
  4216.       /* (xor (comparison foo bar) (const_int 1)) can become the reversed
  4217.      comparison.  */
  4218.       if (XEXP (x, 1) == const1_rtx
  4219.       && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
  4220.       && reversible_comparison_p (XEXP (x, 0)))
  4221.     return gen_rtx_combine (reverse_condition (GET_CODE (XEXP (x, 0))),
  4222.                 mode, XEXP (XEXP (x, 0), 0),
  4223.                 XEXP (XEXP (x, 0), 1));
  4224. #endif
  4225.  
  4226.       /* (xor (comparison foo bar) (const_int sign-bit))
  4227.      when STORE_FLAG_VALUE is the sign bit.  */
  4228.       if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  4229.       && (STORE_FLAG_VALUE
  4230.           == (HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1))
  4231.       && XEXP (x, 1) == const_true_rtx
  4232.       && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
  4233.       && reversible_comparison_p (XEXP (x, 0)))
  4234.     return gen_rtx_combine (reverse_condition (GET_CODE (XEXP (x, 0))),
  4235.                 mode, XEXP (XEXP (x, 0), 0),
  4236.                 XEXP (XEXP (x, 0), 1));
  4237.       break;
  4238.  
  4239.     case ABS:
  4240.       /* (abs (neg <foo>)) -> (abs <foo>) */
  4241.       if (GET_CODE (XEXP (x, 0)) == NEG)
  4242.     SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  4243.  
  4244.       /* If operand is something known to be positive, ignore the ABS.  */
  4245.       if (GET_CODE (XEXP (x, 0)) == FFS || GET_CODE (XEXP (x, 0)) == ABS
  4246.       || ((GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))
  4247.            <= HOST_BITS_PER_WIDE_INT)
  4248.           && ((significant_bits (XEXP (x, 0), GET_MODE (XEXP (x, 0)))
  4249.            & ((HOST_WIDE_INT) 1
  4250.               << (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - 1)))
  4251.           == 0)))
  4252.     return XEXP (x, 0);
  4253.  
  4254.  
  4255.       /* If operand is known to be only -1 or 0, convert ABS to NEG.  */
  4256.       if (num_sign_bit_copies (XEXP (x, 0), mode) == GET_MODE_BITSIZE (mode))
  4257.     {
  4258.       x = gen_rtx_combine (NEG, mode, XEXP (x, 0));
  4259.       goto restart;
  4260.     }
  4261.       break;
  4262.  
  4263.     case FFS:
  4264.       /* (ffs (*_extend <X>)) = (ffs <X>) */
  4265.       if (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND
  4266.       || GET_CODE (XEXP (x, 0)) == ZERO_EXTEND)
  4267.     SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  4268.       break;
  4269.  
  4270.     case FLOAT:
  4271.       /* (float (sign_extend <X>)) = (float <X>).  */
  4272.       if (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)
  4273.     SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  4274.       break;
  4275.  
  4276.     case LSHIFT:
  4277.     case ASHIFT:
  4278.     case LSHIFTRT:
  4279.     case ASHIFTRT:
  4280.     case ROTATE:
  4281.     case ROTATERT:
  4282.       /* If this is a shift by a constant amount, simplify it.  */
  4283.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  4284.     {
  4285.       x = simplify_shift_const (x, code, mode, XEXP (x, 0), 
  4286.                     INTVAL (XEXP (x, 1)));
  4287.       if (GET_CODE (x) != code)
  4288.         goto restart;
  4289.     }
  4290.  
  4291. #ifdef SHIFT_COUNT_TRUNCATED
  4292.       else if (GET_CODE (XEXP (x, 1)) != REG)
  4293.     SUBST (XEXP (x, 1),
  4294.            force_to_mode (XEXP (x, 1), GET_MODE (x),
  4295.                   exact_log2 (GET_MODE_BITSIZE (GET_MODE (x))),
  4296.                   NULL_RTX));
  4297. #endif
  4298.  
  4299.       break;
  4300.     }
  4301.  
  4302.   return x;
  4303. }
  4304.  
  4305. /* We consider ZERO_EXTRACT, SIGN_EXTRACT, and SIGN_EXTEND as "compound
  4306.    operations" because they can be replaced with two more basic operations.
  4307.    ZERO_EXTEND is also considered "compound" because it can be replaced with
  4308.    an AND operation, which is simpler, though only one operation.
  4309.  
  4310.    The function expand_compound_operation is called with an rtx expression
  4311.    and will convert it to the appropriate shifts and AND operations, 
  4312.    simplifying at each stage.
  4313.  
  4314.    The function make_compound_operation is called to convert an expression
  4315.    consisting of shifts and ANDs into the equivalent compound expression.
  4316.    It is the inverse of this function, loosely speaking.  */
  4317.  
  4318. static rtx
  4319. expand_compound_operation (x)
  4320.      rtx x;
  4321. {
  4322.   int pos = 0, len;
  4323.   int unsignedp = 0;
  4324.   int modewidth;
  4325.   rtx tem;
  4326.  
  4327.   switch (GET_CODE (x))
  4328.     {
  4329.     case ZERO_EXTEND:
  4330.       unsignedp = 1;
  4331.     case SIGN_EXTEND:
  4332.       /* We can't necessarily use a const_int for a multiword mode;
  4333.      it depends on implicitly extending the value.
  4334.      Since we don't know the right way to extend it,
  4335.      we can't tell whether the implicit way is right.
  4336.  
  4337.      Even for a mode that is no wider than a const_int,
  4338.      we can't win, because we need to sign extend one of its bits through
  4339.      the rest of it, and we don't know which bit.  */
  4340.       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
  4341.     return x;
  4342.  
  4343.       if (! FAKE_EXTEND_SAFE_P (GET_MODE (XEXP (x, 0)), XEXP (x, 0)))
  4344.     return x;
  4345.  
  4346.       len = GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)));
  4347.       /* If the inner object has VOIDmode (the only way this can happen
  4348.      is if it is a ASM_OPERANDS), we can't do anything since we don't
  4349.      know how much masking to do.  */
  4350.       if (len == 0)
  4351.     return x;
  4352.  
  4353.       break;
  4354.  
  4355.     case ZERO_EXTRACT:
  4356.       unsignedp = 1;
  4357.     case SIGN_EXTRACT:
  4358.       /* If the operand is a CLOBBER, just return it.  */
  4359.       if (GET_CODE (XEXP (x, 0)) == CLOBBER)
  4360.     return XEXP (x, 0);
  4361.  
  4362.       if (GET_CODE (XEXP (x, 1)) != CONST_INT
  4363.       || GET_CODE (XEXP (x, 2)) != CONST_INT
  4364.       || GET_MODE (XEXP (x, 0)) == VOIDmode)
  4365.     return x;
  4366.  
  4367.       len = INTVAL (XEXP (x, 1));
  4368.       pos = INTVAL (XEXP (x, 2));
  4369.  
  4370.       /* If this goes outside the object being extracted, replace the object
  4371.      with a (use (mem ...)) construct that only combine understands
  4372.      and is used only for this purpose.  */
  4373.       if (len + pos > GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))))
  4374.     SUBST (XEXP (x, 0), gen_rtx (USE, GET_MODE (x), XEXP (x, 0)));
  4375.  
  4376. #if BITS_BIG_ENDIAN
  4377.       pos = GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - len - pos;
  4378. #endif
  4379.       break;
  4380.  
  4381.     default:
  4382.       return x;
  4383.     }
  4384.  
  4385.   /* If we reach here, we want to return a pair of shifts.  The inner
  4386.      shift is a left shift of BITSIZE - POS - LEN bits.  The outer
  4387.      shift is a right shift of BITSIZE - LEN bits.  It is arithmetic or
  4388.      logical depending on the value of UNSIGNEDP.
  4389.  
  4390.      If this was a ZERO_EXTEND or ZERO_EXTRACT, this pair of shifts will be
  4391.      converted into an AND of a shift.
  4392.  
  4393.      We must check for the case where the left shift would have a negative
  4394.      count.  This can happen in a case like (x >> 31) & 255 on machines
  4395.      that can't shift by a constant.  On those machines, we would first
  4396.      combine the shift with the AND to produce a variable-position 
  4397.      extraction.  Then the constant of 31 would be substituted in to produce
  4398.      a such a position.  */
  4399.  
  4400.   modewidth = GET_MODE_BITSIZE (GET_MODE (x));
  4401.   if (modewidth >= pos - len)
  4402.     tem = simplify_shift_const (NULL_RTX, unsignedp ? LSHIFTRT : ASHIFTRT,
  4403.                 GET_MODE (x),
  4404.                 simplify_shift_const (NULL_RTX, ASHIFT,
  4405.                               GET_MODE (x),
  4406.                               XEXP (x, 0),
  4407.                               modewidth - pos - len),
  4408.                 modewidth - len);
  4409.  
  4410.   else if (unsignedp && len < HOST_BITS_PER_WIDE_INT)
  4411.     tem = simplify_and_const_int (NULL_RTX, GET_MODE (x),
  4412.                   simplify_shift_const (NULL_RTX, LSHIFTRT,
  4413.                             GET_MODE (x),
  4414.                             XEXP (x, 0), pos),
  4415.                   ((HOST_WIDE_INT) 1 << len) - 1);
  4416.   else
  4417.     /* Any other cases we can't handle.  */
  4418.     return x;
  4419.     
  4420.  
  4421.   /* If we couldn't do this for some reason, return the original
  4422.      expression.  */
  4423.   if (GET_CODE (tem) == CLOBBER)
  4424.     return x;
  4425.  
  4426.   return tem;
  4427. }
  4428.  
  4429. /* X is a SET which contains an assignment of one object into
  4430.    a part of another (such as a bit-field assignment, STRICT_LOW_PART,
  4431.    or certain SUBREGS). If possible, convert it into a series of
  4432.    logical operations.
  4433.  
  4434.    We half-heartedly support variable positions, but do not at all
  4435.    support variable lengths.  */
  4436.  
  4437. static rtx
  4438. expand_field_assignment (x)
  4439.      rtx x;
  4440. {
  4441.   rtx inner;
  4442.   rtx pos;            /* Always counts from low bit. */
  4443.   int len;
  4444.   rtx mask;
  4445.   enum machine_mode compute_mode;
  4446.  
  4447.   /* Loop until we find something we can't simplify.  */
  4448.   while (1)
  4449.     {
  4450.       if (GET_CODE (SET_DEST (x)) == STRICT_LOW_PART
  4451.       && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG)
  4452.     {
  4453.       inner = SUBREG_REG (XEXP (SET_DEST (x), 0));
  4454.       len = GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x), 0)));
  4455.       pos = const0_rtx;
  4456.     }
  4457.       else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
  4458.            && GET_CODE (XEXP (SET_DEST (x), 1)) == CONST_INT)
  4459.     {
  4460.       inner = XEXP (SET_DEST (x), 0);
  4461.       len = INTVAL (XEXP (SET_DEST (x), 1));
  4462.       pos = XEXP (SET_DEST (x), 2);
  4463.  
  4464.       /* If the position is constant and spans the width of INNER,
  4465.          surround INNER  with a USE to indicate this.  */
  4466.       if (GET_CODE (pos) == CONST_INT
  4467.           && INTVAL (pos) + len > GET_MODE_BITSIZE (GET_MODE (inner)))
  4468.         inner = gen_rtx (USE, GET_MODE (SET_DEST (x)), inner);
  4469.  
  4470. #if BITS_BIG_ENDIAN
  4471.       if (GET_CODE (pos) == CONST_INT)
  4472.         pos = GEN_INT (GET_MODE_BITSIZE (GET_MODE (inner)) - len
  4473.                - INTVAL (pos));
  4474.       else if (GET_CODE (pos) == MINUS
  4475.            && GET_CODE (XEXP (pos, 1)) == CONST_INT
  4476.            && (INTVAL (XEXP (pos, 1))
  4477.                == GET_MODE_BITSIZE (GET_MODE (inner)) - len))
  4478.         /* If position is ADJUST - X, new position is X.  */
  4479.         pos = XEXP (pos, 0);
  4480.       else
  4481.         pos = gen_binary (MINUS, GET_MODE (pos),
  4482.                   GEN_INT (GET_MODE_BITSIZE (GET_MODE (inner))
  4483.                        - len),
  4484.                   pos);
  4485. #endif
  4486.     }
  4487.  
  4488.       /* A SUBREG between two modes that occupy the same numbers of words
  4489.      can be done by moving the SUBREG to the source.  */
  4490.       else if (GET_CODE (SET_DEST (x)) == SUBREG
  4491.            && (((GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
  4492.              + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
  4493.            == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x))))
  4494.             + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
  4495.     {
  4496.       x = gen_rtx (SET, VOIDmode, SUBREG_REG (SET_DEST (x)),
  4497.                gen_lowpart_for_combine (GET_MODE (SUBREG_REG (SET_DEST (x))),
  4498.                         SET_SRC (x)));
  4499.       continue;
  4500.     }
  4501.       else
  4502.     break;
  4503.  
  4504.       while (GET_CODE (inner) == SUBREG && subreg_lowpart_p (inner))
  4505.     inner = SUBREG_REG (inner);
  4506.  
  4507.       compute_mode = GET_MODE (inner);
  4508.  
  4509.       /* Compute a mask of LEN bits, if we can do this on the host machine.  */
  4510.       if (len < HOST_BITS_PER_WIDE_INT)
  4511.     mask = GEN_INT (((HOST_WIDE_INT) 1 << len) - 1);
  4512.       else
  4513.     break;
  4514.  
  4515.       /* Now compute the equivalent expression.  Make a copy of INNER
  4516.      for the SET_DEST in case it is a MEM into which we will substitute;
  4517.      we don't want shared RTL in that case.  */
  4518.       x = gen_rtx (SET, VOIDmode, copy_rtx (inner),
  4519.            gen_binary (IOR, compute_mode,
  4520.                    gen_binary (AND, compute_mode,
  4521.                        gen_unary (NOT, compute_mode,
  4522.                               gen_binary (ASHIFT,
  4523.                                   compute_mode,
  4524.                                   mask, pos)),
  4525.                        inner),
  4526.                    gen_binary (ASHIFT, compute_mode,
  4527.                        gen_binary (AND, compute_mode,
  4528.                                gen_lowpart_for_combine
  4529.                                (compute_mode,
  4530.                             SET_SRC (x)),
  4531.                                mask),
  4532.                        pos)));
  4533.     }
  4534.  
  4535.   return x;
  4536. }
  4537.  
  4538. /* Return an RTX for a reference to LEN bits of INNER.  POS is the starting
  4539.    bit position (counted from the LSB) if >= 0; otherwise POS_RTX represents
  4540.    the starting bit position.
  4541.  
  4542.    INNER may be a USE.  This will occur when we started with a bitfield
  4543.    that went outside the boundary of the object in memory, which is
  4544.    allowed on most machines.  To isolate this case, we produce a USE
  4545.    whose mode is wide enough and surround the MEM with it.  The only
  4546.    code that understands the USE is this routine.  If it is not removed,
  4547.    it will cause the resulting insn not to match.
  4548.  
  4549.    UNSIGNEDP is non-zero for an unsigned reference and zero for a 
  4550.    signed reference.
  4551.  
  4552.    IN_DEST is non-zero if this is a reference in the destination of a
  4553.    SET.  This is used when a ZERO_ or SIGN_EXTRACT isn't needed.  If non-zero,
  4554.    a STRICT_LOW_PART will be used, if zero, ZERO_EXTEND or SIGN_EXTEND will
  4555.    be used.
  4556.  
  4557.    IN_COMPARE is non-zero if we are in a COMPARE.  This means that a
  4558.    ZERO_EXTRACT should be built even for bits starting at bit 0.
  4559.  
  4560.    MODE is the desired mode of the result (if IN_DEST == 0).  */
  4561. #ifdef MPW
  4562. #pragma segment COMB02
  4563. #endif
  4564.  
  4565. static rtx
  4566. make_extraction (mode, inner, pos, pos_rtx, len,
  4567.          unsignedp, in_dest, in_compare)
  4568.      enum machine_mode mode;
  4569.      rtx inner;
  4570.      int pos;
  4571.      rtx pos_rtx;
  4572.      int len;
  4573.      int unsignedp;
  4574.      int in_dest, in_compare;
  4575. {
  4576.   /* This mode describes the size of the storage area
  4577.      to fetch the overall value from.  Within that, we
  4578.      ignore the POS lowest bits, etc.  */
  4579.   enum machine_mode is_mode = GET_MODE (inner);
  4580.   enum machine_mode inner_mode;
  4581.   enum machine_mode wanted_mem_mode = byte_mode;
  4582.   enum machine_mode pos_mode = word_mode;
  4583.   enum machine_mode extraction_mode = word_mode;
  4584.   enum machine_mode tmode = mode_for_size (len, MODE_INT, 1);
  4585.   int spans_byte = 0;
  4586.   rtx new = 0;
  4587.  
  4588.   /* Get some information about INNER and get the innermost object.  */
  4589.   if (GET_CODE (inner) == USE)
  4590.     /* (use:SI (mem:QI foo)) stands for (mem:SI foo).  */
  4591.     /* We don't need to adjust the position because we set up the USE
  4592.        to pretend that it was a full-word object.  */
  4593.     spans_byte = 1, inner = XEXP (inner, 0);
  4594.   else if (GET_CODE (inner) == SUBREG && subreg_lowpart_p (inner))
  4595.     {
  4596.       /* If going from (subreg:SI (mem:QI ...)) to (mem:QI ...),
  4597.      consider just the QI as the memory to extract from.
  4598.      The subreg adds or removes high bits; its mode is
  4599.      irrelevant to the meaning of this extraction,
  4600.      since POS and LEN count from the lsb.  */
  4601.       if (GET_CODE (SUBREG_REG (inner)) == MEM)
  4602.     is_mode = GET_MODE (SUBREG_REG (inner));
  4603.       inner = SUBREG_REG (inner);
  4604.     }
  4605.  
  4606.   inner_mode = GET_MODE (inner);
  4607.  
  4608.   if (pos_rtx && GET_CODE (pos_rtx) == CONST_INT)
  4609.     pos = INTVAL (pos_rtx);
  4610.  
  4611.   /* See if this can be done without an extraction.  We never can if the
  4612.      width of the field is not the same as that of some integer mode. For
  4613.      registers, we can only avoid the extraction if the position is at the
  4614.      low-order bit and this is either not in the destination or we have the
  4615.      appropriate STRICT_LOW_PART operation available.
  4616.  
  4617.      For MEM, we can avoid an extract if the field starts on an appropriate
  4618.      boundary and we can change the mode of the memory reference.  However,
  4619.      we cannot directly access the MEM if we have a USE and the underlying
  4620.      MEM is not TMODE.  This combination means that MEM was being used in a
  4621.      context where bits outside its mode were being referenced; that is only
  4622.      valid in bit-field insns.  */
  4623.  
  4624.   if (tmode != BLKmode
  4625.       && ! (spans_byte && inner_mode != tmode)
  4626.       && ((pos == 0 && GET_CODE (inner) != MEM
  4627.        && (! in_dest
  4628.            || (GET_CODE (inner) == REG
  4629.            && (movstrict_optab->handlers[(int) tmode].insn_code
  4630.                != CODE_FOR_nothing))))
  4631.       || (GET_CODE (inner) == MEM && pos >= 0
  4632.           && (pos
  4633.           % (STRICT_ALIGNMENT ? GET_MODE_ALIGNMENT (tmode)
  4634.              : BITS_PER_UNIT)) == 0
  4635.           /* We can't do this if we are widening INNER_MODE (it
  4636.          may not be aligned, for one thing).  */
  4637.           && GET_MODE_BITSIZE (inner_mode) >= GET_MODE_BITSIZE (tmode)
  4638.           && (inner_mode == tmode
  4639.           || (! mode_dependent_address_p (XEXP (inner, 0))
  4640.               && ! MEM_VOLATILE_P (inner))))))
  4641.     {
  4642.       /* If INNER is a MEM, make a new MEM that encompasses just the desired
  4643.      field.  If the original and current mode are the same, we need not
  4644.      adjust the offset.  Otherwise, we do if bytes big endian.  
  4645.  
  4646.      If INNER is not a MEM, get a piece consisting of the just the field
  4647.      of interest (in this case POS must be 0).  */
  4648.  
  4649.       if (GET_CODE (inner) == MEM)
  4650.     {
  4651.       int offset;
  4652.       /* POS counts from lsb, but make OFFSET count in memory order.  */
  4653.       if (BYTES_BIG_ENDIAN)
  4654.         offset = (GET_MODE_BITSIZE (is_mode) - len - pos) / BITS_PER_UNIT;
  4655.       else
  4656.         offset = pos / BITS_PER_UNIT;
  4657.  
  4658.       new = gen_rtx (MEM, tmode, plus_constant (XEXP (inner, 0), offset));
  4659.       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (inner);
  4660.       MEM_VOLATILE_P (new) = MEM_VOLATILE_P (inner);
  4661.       MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (inner);
  4662.     }
  4663.       else if (GET_CODE (inner) == REG)
  4664.     /* We can't call gen_lowpart_for_combine here since we always want
  4665.        a SUBREG and it would sometimes return a new hard register.  */
  4666.     new = gen_rtx (SUBREG, tmode, inner,
  4667.                (WORDS_BIG_ENDIAN
  4668.             && GET_MODE_SIZE (inner_mode) > UNITS_PER_WORD
  4669.             ? ((GET_MODE_SIZE (inner_mode) - GET_MODE_SIZE (tmode))
  4670.                / UNITS_PER_WORD)
  4671.             : 0));
  4672.       else
  4673.     new = force_to_mode (inner, tmode, len, NULL_RTX);
  4674.  
  4675.       /* If this extraction is going into the destination of a SET, 
  4676.      make a STRICT_LOW_PART unless we made a MEM.  */
  4677.  
  4678.       if (in_dest)
  4679.     return (GET_CODE (new) == MEM ? new
  4680.         : (GET_CODE (new) != SUBREG
  4681.            ? gen_rtx (CLOBBER, tmode, const0_rtx)
  4682.            : gen_rtx_combine (STRICT_LOW_PART, VOIDmode, new)));
  4683.  
  4684.       /* Otherwise, sign- or zero-extend unless we already are in the
  4685.      proper mode.  */
  4686.  
  4687.       return (mode == tmode ? new
  4688.           : gen_rtx_combine (unsignedp ? ZERO_EXTEND : SIGN_EXTEND,
  4689.                  mode, new));
  4690.     }
  4691.  
  4692.   /* Unless this is a COMPARE or we have a funny memory reference,
  4693.      don't do anything with zero-extending field extracts starting at
  4694.      the low-order bit since they are simple AND operations.  */
  4695.   if (pos == 0 && ! in_dest && ! in_compare && ! spans_byte && unsignedp)
  4696.     return 0;
  4697.  
  4698.   /* Get the mode to use should INNER be a MEM, the mode for the position,
  4699.      and the mode for the result.  */
  4700. #ifdef HAVE_insv
  4701.   if (in_dest)
  4702.     {
  4703.       wanted_mem_mode = insn_operand_mode[(int) CODE_FOR_insv][0];
  4704.       pos_mode = insn_operand_mode[(int) CODE_FOR_insv][2];
  4705.       extraction_mode = insn_operand_mode[(int) CODE_FOR_insv][3];
  4706.     }
  4707. #endif
  4708.  
  4709. #ifdef HAVE_extzv
  4710.   if (! in_dest && unsignedp)
  4711.     {
  4712.       wanted_mem_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
  4713.       pos_mode = insn_operand_mode[(int) CODE_FOR_extzv][3];
  4714.       extraction_mode = insn_operand_mode[(int) CODE_FOR_extzv][0];
  4715.     }
  4716. #endif
  4717.  
  4718. #ifdef HAVE_extv
  4719.   if (! in_dest && ! unsignedp)
  4720.     {
  4721.       wanted_mem_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
  4722.       pos_mode = insn_operand_mode[(int) CODE_FOR_extv][3];
  4723.       extraction_mode = insn_operand_mode[(int) CODE_FOR_extv][0];
  4724.     }
  4725. #endif
  4726.  
  4727.   /* Never narrow an object, since that might not be safe.  */
  4728.  
  4729.   if (mode != VOIDmode
  4730.       && GET_MODE_SIZE (extraction_mode) < GET_MODE_SIZE (mode))
  4731.     extraction_mode = mode;
  4732.  
  4733.   if (pos_rtx && GET_MODE (pos_rtx) != VOIDmode
  4734.       && GET_MODE_SIZE (pos_mode) < GET_MODE_SIZE (GET_MODE (pos_rtx)))
  4735.     pos_mode = GET_MODE (pos_rtx);
  4736.  
  4737.   /* If this is not from memory or we have to change the mode of memory and
  4738.      cannot, the desired mode is EXTRACTION_MODE.  */
  4739.   if (GET_CODE (inner) != MEM
  4740.       || (inner_mode != wanted_mem_mode
  4741.       && (mode_dependent_address_p (XEXP (inner, 0))
  4742.           || MEM_VOLATILE_P (inner))))
  4743.     wanted_mem_mode = extraction_mode;
  4744.  
  4745. #if BITS_BIG_ENDIAN
  4746.   /* If position is constant, compute new position.  Otherwise, build
  4747.      subtraction.  */
  4748.   if (pos >= 0)
  4749.     pos = (MAX (GET_MODE_BITSIZE (is_mode), GET_MODE_BITSIZE (wanted_mem_mode))
  4750.        - len - pos);
  4751.   else
  4752.     pos_rtx
  4753.       = gen_rtx_combine (MINUS, GET_MODE (pos_rtx),
  4754.              GEN_INT (MAX (GET_MODE_BITSIZE (is_mode),
  4755.                        GET_MODE_BITSIZE (wanted_mem_mode))
  4756.                   - len),
  4757.              pos_rtx);
  4758. #endif
  4759.  
  4760.   /* If INNER has a wider mode, make it smaller.  If this is a constant
  4761.      extract, try to adjust the byte to point to the byte containing
  4762.      the value.  */
  4763.   if (wanted_mem_mode != VOIDmode
  4764.       && GET_MODE_SIZE (wanted_mem_mode) < GET_MODE_SIZE (is_mode)
  4765.       && ((GET_CODE (inner) == MEM
  4766.        && (inner_mode == wanted_mem_mode
  4767.            || (! mode_dependent_address_p (XEXP (inner, 0))
  4768.            && ! MEM_VOLATILE_P (inner))))))
  4769.     {
  4770.       int offset = 0;
  4771.  
  4772.       /* The computations below will be correct if the machine is big
  4773.      endian in both bits and bytes or little endian in bits and bytes.
  4774.      If it is mixed, we must adjust.  */
  4775.          
  4776. #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
  4777.       if (! spans_byte && is_mode != wanted_mem_mode)
  4778.     offset = (GET_MODE_SIZE (is_mode)
  4779.           - GET_MODE_SIZE (wanted_mem_mode) - offset);
  4780. #endif
  4781.  
  4782.       /* If bytes are big endian and we had a paradoxical SUBREG, we must
  4783.      adjust OFFSET to compensate. */
  4784. #if BYTES_BIG_ENDIAN
  4785.       if (! spans_byte
  4786.       && GET_MODE_SIZE (inner_mode) < GET_MODE_SIZE (is_mode))
  4787.     offset -= GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (inner_mode);
  4788. #endif
  4789.  
  4790.       /* If this is a constant position, we can move to the desired byte.  */
  4791.       if (pos >= 0)
  4792.     {
  4793.       offset += pos / BITS_PER_UNIT;
  4794.       pos %= GET_MODE_BITSIZE (wanted_mem_mode);
  4795.     }
  4796.  
  4797.       if (offset != 0 || inner_mode != wanted_mem_mode)
  4798.     {
  4799.       rtx newmem = gen_rtx (MEM, wanted_mem_mode,
  4800.                 plus_constant (XEXP (inner, 0), offset));
  4801.       RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (inner);
  4802.       MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (inner);
  4803.       MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (inner);
  4804.       inner = newmem;
  4805.     }
  4806.     }
  4807.  
  4808.   /* If INNER is not memory, we can always get it into the proper mode. */
  4809.   else if (GET_CODE (inner) != MEM)
  4810.     inner = force_to_mode (inner, extraction_mode,
  4811.                (pos < 0 ? GET_MODE_BITSIZE (extraction_mode)
  4812.                 : len + pos),
  4813.                NULL_RTX);
  4814.  
  4815.   /* Adjust mode of POS_RTX, if needed.  If we want a wider mode, we
  4816.      have to zero extend.  Otherwise, we can just use a SUBREG.  */
  4817.   if (pos < 0
  4818.       && GET_MODE_SIZE (pos_mode) > GET_MODE_SIZE (GET_MODE (pos_rtx)))
  4819.     pos_rtx = gen_rtx_combine (ZERO_EXTEND, pos_mode, pos_rtx);
  4820.   else if (pos < 0
  4821.        && GET_MODE_SIZE (pos_mode) < GET_MODE_SIZE (GET_MODE (pos_rtx)))
  4822.     pos_rtx = gen_lowpart_for_combine (pos_mode, pos_rtx);
  4823.  
  4824.   /* Make POS_RTX unless we already have it and it is correct.  */
  4825.   if (pos_rtx == 0 || (pos >= 0 && INTVAL (pos_rtx) != pos))
  4826.     pos_rtx = GEN_INT (pos);
  4827.  
  4828.   /* Make the required operation.  See if we can use existing rtx.  */
  4829.   new = gen_rtx_combine (unsignedp ? ZERO_EXTRACT : SIGN_EXTRACT,
  4830.              extraction_mode, inner, GEN_INT (len), pos_rtx);
  4831.   if (! in_dest)
  4832.     new = gen_lowpart_for_combine (mode, new);
  4833.  
  4834.   return new;
  4835. }
  4836.  
  4837. /* Look at the expression rooted at X.  Look for expressions
  4838.    equivalent to ZERO_EXTRACT, SIGN_EXTRACT, ZERO_EXTEND, SIGN_EXTEND.
  4839.    Form these expressions.
  4840.  
  4841.    Return the new rtx, usually just X.
  4842.  
  4843.    Also, for machines like the Vax that don't have logical shift insns,
  4844.    try to convert logical to arithmetic shift operations in cases where
  4845.    they are equivalent.  This undoes the canonicalizations to logical
  4846.    shifts done elsewhere.
  4847.  
  4848.    We try, as much as possible, to re-use rtl expressions to save memory.
  4849.  
  4850.    IN_CODE says what kind of expression we are processing.  Normally, it is
  4851.    SET.  In a memory address (inside a MEM, PLUS or minus, the latter two
  4852.    being kludges), it is MEM.  When processing the arguments of a comparison
  4853.    or a COMPARE against zero, it is COMPARE.  */
  4854.  
  4855. static rtx
  4856. make_compound_operation (x, in_code)
  4857.      rtx x;
  4858.      enum rtx_code in_code;
  4859. {
  4860.   enum rtx_code code = GET_CODE (x);
  4861.   enum machine_mode mode = GET_MODE (x);
  4862.   int mode_width = GET_MODE_BITSIZE (mode);
  4863.   enum rtx_code next_code;
  4864.   int i, count;
  4865.   rtx new = 0;
  4866.   char *fmt;
  4867.  
  4868.   /* Select the code to be used in recursive calls.  Once we are inside an
  4869.      address, we stay there.  If we have a comparison, set to COMPARE,
  4870.      but once inside, go back to our default of SET.  */
  4871.  
  4872.   next_code = (code == MEM || code == PLUS || code == MINUS ? MEM
  4873.            : ((code == COMPARE || GET_RTX_CLASS (code) == '<')
  4874.           && XEXP (x, 1) == const0_rtx) ? COMPARE
  4875.            : in_code == COMPARE ? SET : in_code);
  4876.  
  4877.   /* Process depending on the code of this operation.  If NEW is set
  4878.      non-zero, it will be returned.  */
  4879.  
  4880.   switch (code)
  4881.     {
  4882.     case ASHIFT:
  4883.     case LSHIFT:
  4884.       /* Convert shifts by constants into multiplications if inside
  4885.      an address.  */
  4886.       if (in_code == MEM && GET_CODE (XEXP (x, 1)) == CONST_INT
  4887.       && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT
  4888.       && INTVAL (XEXP (x, 1)) >= 0)
  4889.     new = gen_rtx_combine (MULT, mode, XEXP (x, 0),
  4890.                    GEN_INT ((HOST_WIDE_INT) 1
  4891.                     << INTVAL (XEXP (x, 1))));
  4892.       break;
  4893.  
  4894.     case AND:
  4895.       /* If the second operand is not a constant, we can't do anything
  4896.      with it.  */
  4897.       if (GET_CODE (XEXP (x, 1)) != CONST_INT)
  4898.     break;
  4899.  
  4900.       /* If the constant is a power of two minus one and the first operand
  4901.      is a logical right shift, make an extraction.  */
  4902.       if (GET_CODE (XEXP (x, 0)) == LSHIFTRT
  4903.       && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0)
  4904.     new = make_extraction (mode, XEXP (XEXP (x, 0), 0), -1,
  4905.                    XEXP (XEXP (x, 0), 1), i, 1,
  4906.                    0, in_code == COMPARE);
  4907.  
  4908.       /* Same as previous, but for (subreg (lshiftrt ...)) in first op.  */
  4909.       else if (GET_CODE (XEXP (x, 0)) == SUBREG
  4910.            && subreg_lowpart_p (XEXP (x, 0))
  4911.            && GET_CODE (SUBREG_REG (XEXP (x, 0))) == LSHIFTRT
  4912.            && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0)
  4913.     new = make_extraction (GET_MODE (SUBREG_REG (XEXP (x, 0))),
  4914.                    XEXP (SUBREG_REG (XEXP (x, 0)), 0), -1,
  4915.                    XEXP (SUBREG_REG (XEXP (x, 0)), 1), i, 1,
  4916.                    0, in_code == COMPARE);
  4917.  
  4918.  
  4919.       /* If we are have (and (rotate X C) M) and C is larger than the number
  4920.      of bits in M, this is an extraction.  */
  4921.  
  4922.       else if (GET_CODE (XEXP (x, 0)) == ROTATE
  4923.            && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  4924.            && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0
  4925.            && i <= INTVAL (XEXP (XEXP (x, 0), 1)))
  4926.     new = make_extraction (mode, XEXP (XEXP (x, 0), 0),
  4927.                    (GET_MODE_BITSIZE (mode)
  4928.                 - INTVAL (XEXP (XEXP (x, 0), 1))),
  4929.                    NULL_RTX, i, 1, 0, in_code == COMPARE);
  4930.  
  4931.       /* On machines without logical shifts, if the operand of the AND is
  4932.      a logical shift and our mask turns off all the propagated sign
  4933.      bits, we can replace the logical shift with an arithmetic shift.  */
  4934.       else if (ashr_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
  4935.            && (lshr_optab->handlers[(int) mode].insn_code
  4936.            == CODE_FOR_nothing)
  4937.            && GET_CODE (XEXP (x, 0)) == LSHIFTRT
  4938.            && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  4939.            && INTVAL (XEXP (XEXP (x, 0), 1)) >= 0
  4940.            && INTVAL (XEXP (XEXP (x, 0), 1)) < HOST_BITS_PER_WIDE_INT
  4941.            && mode_width <= HOST_BITS_PER_WIDE_INT)
  4942.     {
  4943.       unsigned HOST_WIDE_INT mask = GET_MODE_MASK (mode);
  4944.  
  4945.       mask >>= INTVAL (XEXP (XEXP (x, 0), 1));
  4946.       if ((INTVAL (XEXP (x, 1)) & ~mask) == 0)
  4947.         SUBST (XEXP (x, 0),
  4948.            gen_rtx_combine (ASHIFTRT, mode, XEXP (XEXP (x, 0), 0),
  4949.                     XEXP (XEXP (x, 0), 1)));
  4950.     }
  4951.  
  4952.       /* If the constant is one less than a power of two, this might be
  4953.      representable by an extraction even if no shift is present.
  4954.      If it doesn't end up being a ZERO_EXTEND, we will ignore it unless
  4955.      we are in a COMPARE.  */
  4956.       else if ((i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0)
  4957.     new = make_extraction (mode, XEXP (x, 0), 0, NULL_RTX, i, 1,
  4958.                    0, in_code == COMPARE);
  4959.  
  4960.       /* If we are in a comparison and this is an AND with a power of two,
  4961.      convert this into the appropriate bit extract.  */
  4962.       else if (in_code == COMPARE
  4963.            && (i = exact_log2 (INTVAL (XEXP (x, 1)))) >= 0)
  4964.     new = make_extraction (mode, XEXP (x, 0), i, NULL_RTX, 1, 1, 0, 1);
  4965.  
  4966.       break;
  4967.  
  4968.     case LSHIFTRT:
  4969.       /* If the sign bit is known to be zero, replace this with an
  4970.      arithmetic shift.  */
  4971.       if (ashr_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing
  4972.       && lshr_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
  4973.       && mode_width <= HOST_BITS_PER_WIDE_INT
  4974.       && (significant_bits (XEXP (x, 0), mode)
  4975.           & (1 << (mode_width - 1))) == 0)
  4976.     {
  4977.       new = gen_rtx_combine (ASHIFTRT, mode, XEXP (x, 0), XEXP (x, 1));
  4978.       break;
  4979.     }
  4980.  
  4981.       /* ... fall through ... */
  4982.  
  4983.     case ASHIFTRT:
  4984.       /* If we have (ashiftrt (ashift foo C1) C2) with C2 >= C1,
  4985.      this is a SIGN_EXTRACT.  */
  4986.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  4987.       && GET_CODE (XEXP (x, 0)) == ASHIFT
  4988.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  4989.       && INTVAL (XEXP (x, 1)) >= INTVAL (XEXP (XEXP (x, 0), 1)))
  4990.     new = make_extraction (mode, XEXP (XEXP (x, 0), 0),
  4991.                    (INTVAL (XEXP (x, 1))
  4992.                 - INTVAL (XEXP (XEXP (x, 0), 1))),
  4993.                    NULL_RTX, mode_width - INTVAL (XEXP (x, 1)),
  4994.                    code == LSHIFTRT, 0, in_code == COMPARE);
  4995.  
  4996.       /* Similarly if we have (ashifrt (OP (ashift foo C1) C3) C2).  In these
  4997.      cases, we are better off returning a SIGN_EXTEND of the operation.  */
  4998.  
  4999.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  5000.       && (GET_CODE (XEXP (x, 0)) == IOR || GET_CODE (XEXP (x, 0)) == AND
  5001.           || GET_CODE (XEXP (x, 0)) == XOR
  5002.           || GET_CODE (XEXP (x, 0)) == PLUS)
  5003.       && GET_CODE (XEXP (XEXP (x, 0), 0)) == ASHIFT
  5004.       && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
  5005.       && INTVAL (XEXP (x, 1)) >= INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1))
  5006.       && INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)) < HOST_BITS_PER_WIDE_INT
  5007.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  5008.       && (INTVAL (XEXP (XEXP (x, 0), 1))
  5009.           & (((HOST_WIDE_INT) 1
  5010.           << INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1))) - 1)) == 0)
  5011.     {
  5012.       HOST_WIDE_INT newop1
  5013.         = (INTVAL (XEXP (XEXP (x, 0), 1))
  5014.            >> INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)));
  5015.  
  5016.       new = make_extraction (mode,
  5017.                  gen_binary (GET_CODE (XEXP (x, 0)), mode,
  5018.                          XEXP (XEXP (XEXP (x, 0), 0), 0),
  5019.                          GEN_INT (newop1)),
  5020.                  (INTVAL (XEXP (x, 1))
  5021.                   - INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1))),
  5022.                  NULL_RTX, mode_width - INTVAL (XEXP (x, 1)),
  5023.                  code == LSHIFTRT, 0, in_code == COMPARE);
  5024.     }
  5025.  
  5026.       /* Similarly for (ashiftrt (neg (ashift FOO C1)) C2).  */
  5027.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  5028.       && GET_CODE (XEXP (x, 0)) == NEG
  5029.       && GET_CODE (XEXP (XEXP (x, 0), 0)) == ASHIFT
  5030.       && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
  5031.       && INTVAL (XEXP (x, 1)) >= INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
  5032.     new = make_extraction (mode,
  5033.                    gen_unary (GET_CODE (XEXP (x, 0)), mode,
  5034.                       XEXP (XEXP (XEXP (x, 0), 0), 0)),
  5035.                    (INTVAL (XEXP (x, 1))
  5036.                 - INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1))),
  5037.                    NULL_RTX, mode_width - INTVAL (XEXP (x, 1)),
  5038.                    code == LSHIFTRT, 0, in_code == COMPARE);
  5039.       break;
  5040.     }
  5041.  
  5042.   if (new)
  5043.     {
  5044.       x = gen_lowpart_for_combine (mode, new);
  5045.       code = GET_CODE (x);
  5046.     }
  5047.  
  5048.   /* Now recursively process each operand of this operation.  */
  5049.   fmt = GET_RTX_FORMAT (code);
  5050.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  5051.     if (fmt[i] == 'e')
  5052.       {
  5053.     new = make_compound_operation (XEXP (x, i), next_code);
  5054.     SUBST (XEXP (x, i), new);
  5055.       }
  5056.  
  5057.   return x;
  5058. }
  5059.  
  5060. /* Given M see if it is a value that would select a field of bits
  5061.     within an item, but not the entire word.  Return -1 if not.
  5062.     Otherwise, return the starting position of the field, where 0 is the
  5063.     low-order bit.
  5064.  
  5065.    *PLEN is set to the length of the field.  */
  5066.  
  5067. static int
  5068. get_pos_from_mask (m, plen)
  5069.      unsigned HOST_WIDE_INT m;
  5070.      int *plen;
  5071. {
  5072.   /* Get the bit number of the first 1 bit from the right, -1 if none.  */
  5073.   int pos = exact_log2 (m & - m);
  5074.  
  5075.   if (pos < 0)
  5076.     return -1;
  5077.  
  5078.   /* Now shift off the low-order zero bits and see if we have a power of
  5079.      two minus 1.  */
  5080.   *plen = exact_log2 ((m >> pos) + 1);
  5081.  
  5082.   if (*plen <= 0)
  5083.     return -1;
  5084.  
  5085.   return pos;
  5086. }
  5087.  
  5088. /* Rewrite X so that it is an expression in MODE.  We only care about the
  5089.    low-order BITS bits so we can ignore AND operations that just clear
  5090.    higher-order bits.
  5091.  
  5092.    Also, if REG is non-zero and X is a register equal in value to REG, 
  5093.    replace X with REG.  */
  5094.  
  5095. static rtx
  5096. force_to_mode (x, mode, bits, reg)
  5097.      rtx x;
  5098.      enum machine_mode mode;
  5099.      int bits;
  5100.      rtx reg;
  5101. {
  5102.   enum rtx_code code = GET_CODE (x);
  5103.   enum machine_mode op_mode = mode;
  5104.  
  5105.   /* If X is narrower than MODE or if BITS is larger than the size of MODE,
  5106.      just get X in the proper mode.  */
  5107.  
  5108.   if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode)
  5109.       || bits > GET_MODE_BITSIZE (mode))
  5110.     return gen_lowpart_for_combine (mode, x);
  5111.  
  5112.   switch (code)
  5113.     {
  5114.     case SIGN_EXTEND:
  5115.     case ZERO_EXTEND:
  5116.     case ZERO_EXTRACT:
  5117.     case SIGN_EXTRACT:
  5118.       x = expand_compound_operation (x);
  5119.       if (GET_CODE (x) != code)
  5120.     return force_to_mode (x, mode, bits, reg);
  5121.       break;
  5122.  
  5123.     case REG:
  5124.       if (reg != 0 && (rtx_equal_p (get_last_value (reg), x)
  5125.                || rtx_equal_p (reg, get_last_value (x))))
  5126.     x = reg;
  5127.       break;
  5128.  
  5129.     case CONST_INT:
  5130.       if (bits < HOST_BITS_PER_WIDE_INT)
  5131.     x = GEN_INT (INTVAL (x) & (((HOST_WIDE_INT) 1 << bits) - 1));
  5132.       return x;
  5133.  
  5134.     case SUBREG:
  5135.       /* Ignore low-order SUBREGs. */
  5136.       if (subreg_lowpart_p (x))
  5137.     return force_to_mode (SUBREG_REG (x), mode, bits, reg);
  5138.       break;
  5139.  
  5140.     case AND:
  5141.       /* If this is an AND with a constant.  Otherwise, we fall through to
  5142.      do the general binary case.  */
  5143.  
  5144.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  5145.     {
  5146.       HOST_WIDE_INT mask = INTVAL (XEXP (x, 1));
  5147.       int len = exact_log2 (mask + 1);
  5148.       rtx op = XEXP (x, 0);
  5149.  
  5150.       /* If this is masking some low-order bits, we may be able to
  5151.          impose a stricter constraint on what bits of the operand are
  5152.          required.  */
  5153.  
  5154.       op = force_to_mode (op, mode, len > 0 ? MIN (len, bits) : bits,
  5155.                   reg);
  5156.  
  5157.       if (bits < HOST_BITS_PER_WIDE_INT)
  5158.         mask &= ((HOST_WIDE_INT) 1 << bits) - 1;
  5159.  
  5160.       /* If we have no AND in MODE, use the original mode for the
  5161.          operation.  */
  5162.  
  5163.       if (and_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
  5164.         op_mode = GET_MODE (x);
  5165.  
  5166.       x = simplify_and_const_int (x, op_mode, op, mask);
  5167.  
  5168.       /* If X is still an AND, see if it is an AND with a mask that
  5169.          is just some low-order bits.  If so, and it is BITS wide (it
  5170.          can't be wider), we don't need it.  */
  5171.  
  5172.       if (GET_CODE (x) == AND && GET_CODE (XEXP (x, 1)) == CONST_INT
  5173.           && bits < HOST_BITS_PER_WIDE_INT
  5174.           && INTVAL (XEXP (x, 1)) == ((HOST_WIDE_INT) 1 << bits) - 1)
  5175.         x = XEXP (x, 0);
  5176.  
  5177.       break;
  5178.     }
  5179.  
  5180.       /* ... fall through ... */
  5181.  
  5182.     case PLUS:
  5183.     case MINUS:
  5184.     case MULT:
  5185.     case IOR:
  5186.     case XOR:
  5187.       /* For most binary operations, just propagate into the operation and
  5188.      change the mode if we have an operation of that mode.  */
  5189.  
  5190.       if ((code == PLUS
  5191.        && add_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
  5192.       || (code == MINUS
  5193.           && sub_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
  5194.       || (code == MULT && (smul_optab->handlers[(int) mode].insn_code
  5195.                    == CODE_FOR_nothing))
  5196.       || (code == AND
  5197.           && and_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
  5198.       || (code == IOR
  5199.           && ior_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
  5200.       || (code == XOR && (xor_optab->handlers[(int) mode].insn_code
  5201.                   == CODE_FOR_nothing)))
  5202.     op_mode = GET_MODE (x);
  5203.  
  5204.       x = gen_binary (code, op_mode,
  5205.               gen_lowpart_for_combine (op_mode,
  5206.                            force_to_mode (XEXP (x, 0),
  5207.                                   mode, bits,
  5208.                                   reg)),
  5209.               gen_lowpart_for_combine (op_mode,
  5210.                            force_to_mode (XEXP (x, 1),
  5211.                                   mode, bits,
  5212.                                   reg)));
  5213.       break;
  5214.  
  5215.     case ASHIFT:
  5216.     case LSHIFT:
  5217.       /* For left shifts, do the same, but just for the first operand.
  5218.      If the shift count is a constant, we need even fewer bits of the
  5219.      first operand.  */
  5220.  
  5221.       if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) < bits)
  5222.     bits -= INTVAL (XEXP (x, 1));
  5223.  
  5224.       if ((code == ASHIFT
  5225.        && ashl_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
  5226.       || (code == LSHIFT && (lshl_optab->handlers[(int) mode].insn_code
  5227.                  == CODE_FOR_nothing)))
  5228.     op_mode = GET_MODE (x);
  5229.  
  5230.       x =  gen_binary (code, op_mode,
  5231.                gen_lowpart_for_combine (op_mode,
  5232.                         force_to_mode (XEXP (x, 0),
  5233.                                    mode, bits,
  5234.                                    reg)),
  5235.                XEXP (x, 1));
  5236.       break;
  5237.  
  5238.     case LSHIFTRT:
  5239.       /* Here we can only do something if the shift count is a constant and
  5240.      the count plus BITS is no larger than the width of MODE, we can do
  5241.      the shift in MODE.  */
  5242.  
  5243.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  5244.       && INTVAL (XEXP (x, 1)) + bits <= GET_MODE_BITSIZE (mode))
  5245.     {
  5246.       rtx inner = force_to_mode (XEXP (x, 0), mode,
  5247.                      bits + INTVAL (XEXP (x, 1)), reg);
  5248.  
  5249.       if (lshr_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
  5250.         op_mode = GET_MODE (x);
  5251.  
  5252.       x = gen_binary (LSHIFTRT, op_mode,
  5253.               gen_lowpart_for_combine (op_mode, inner),
  5254.               XEXP (x, 1));
  5255.     }
  5256.       break;
  5257.  
  5258.     case ASHIFTRT:
  5259.       /* If this is a sign-extension operation that just affects bits
  5260.      we don't care about, remove it.  */
  5261.  
  5262.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  5263.       && INTVAL (XEXP (x, 1)) >= 0
  5264.       && INTVAL (XEXP (x, 1)) <= GET_MODE_BITSIZE (GET_MODE (x)) - bits
  5265.       && GET_CODE (XEXP (x, 0)) == ASHIFT
  5266.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  5267.       && INTVAL (XEXP (XEXP (x, 0), 1)) == INTVAL (XEXP (x, 1)))
  5268.     return force_to_mode (XEXP (XEXP (x, 0), 0), mode, bits, reg);
  5269.       break;
  5270.  
  5271.     case NEG:
  5272.     case NOT:
  5273.       if ((code == NEG
  5274.        && neg_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
  5275.       || (code == NOT && (one_cmpl_optab->handlers[(int) mode].insn_code
  5276.                   == CODE_FOR_nothing)))
  5277.     op_mode = GET_MODE (x);
  5278.  
  5279.       /* Handle these similarly to the way we handle most binary operations. */
  5280.       x = gen_unary (code, op_mode,
  5281.              gen_lowpart_for_combine (op_mode,
  5282.                           force_to_mode (XEXP (x, 0), mode,
  5283.                                  bits, reg)));
  5284.       break;
  5285.  
  5286.     case IF_THEN_ELSE:
  5287.       /* We have no way of knowing if the IF_THEN_ELSE can itself be
  5288.      written in a narrower mode.  We play it safe and do not do so.  */
  5289.  
  5290.       SUBST (XEXP (x, 1),
  5291.          gen_lowpart_for_combine (GET_MODE (x),
  5292.                       force_to_mode (XEXP (x, 1), mode,
  5293.                              bits, reg)));
  5294.       SUBST (XEXP (x, 2),
  5295.          gen_lowpart_for_combine (GET_MODE (x),
  5296.                       force_to_mode (XEXP (x, 2), mode,
  5297.                              bits, reg)));
  5298.       break;
  5299.     }
  5300.  
  5301.   /* Ensure we return a value of the proper mode.  */
  5302.   return gen_lowpart_for_combine (mode, x);
  5303. }
  5304.  
  5305. /* Return the value of expression X given the fact that condition COND
  5306.    is known to be true when applied to REG as its first operand and VAL
  5307.    as its second.  X is known to not be shared and so can be modified in
  5308.    place.
  5309.  
  5310.    We only handle the simplest cases, and specifically those cases that
  5311.    arise with IF_THEN_ELSE expressions.  */
  5312.  
  5313. static rtx
  5314. known_cond (x, cond, reg, val)
  5315.      rtx x;
  5316.      enum rtx_code cond;
  5317.      rtx reg, val;
  5318. {
  5319.   enum rtx_code code = GET_CODE (x);
  5320.   rtx new, temp;
  5321.   char *fmt;
  5322.   int i, j;
  5323.  
  5324.   if (side_effects_p (x))
  5325.     return x;
  5326.  
  5327.   if (cond == EQ && rtx_equal_p (x, reg))
  5328.     return val;
  5329.  
  5330.   /* If X is (abs REG) and we know something about REG's relationship
  5331.      with zero, we may be able to simplify this.  */
  5332.  
  5333.   if (code == ABS && rtx_equal_p (XEXP (x, 0), reg) && val == const0_rtx)
  5334.     switch (cond)
  5335.       {
  5336.       case GE:  case GT:  case EQ:
  5337.     return XEXP (x, 0);
  5338.       case LT:  case LE:
  5339.     return gen_unary (NEG, GET_MODE (XEXP (x, 0)), XEXP (x, 0));
  5340.       }
  5341.  
  5342.   /* The only other cases we handle are MIN, MAX, and comparisons if the
  5343.      operands are the same as REG and VAL.  */
  5344.  
  5345.   else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == 'c')
  5346.     {
  5347.       if (rtx_equal_p (XEXP (x, 0), val))
  5348.     cond = swap_condition (cond), temp = val, val = reg, reg = temp;
  5349.  
  5350.       if (rtx_equal_p (XEXP (x, 0), reg) && rtx_equal_p (XEXP (x, 1), val))
  5351.     {
  5352.       if (GET_RTX_CLASS (code) == '<')
  5353.         return (comparison_dominates_p (cond, code) ? const_true_rtx
  5354.             : (comparison_dominates_p (cond,
  5355.                            reverse_condition (code))
  5356.                ? const0_rtx : x));
  5357.  
  5358.       else if (code == SMAX || code == SMIN
  5359.            || code == UMIN || code == UMAX)
  5360.         {
  5361.           int unsignedp = (code == UMIN || code == UMAX);
  5362.  
  5363.           if (code == SMAX || code == UMAX)
  5364.         cond = reverse_condition (cond);
  5365.  
  5366.           switch (cond)
  5367.         {
  5368.         case GE:   case GT:
  5369.           return unsignedp ? x : XEXP (x, 1);
  5370.         case LE:   case LT:
  5371.           return unsignedp ? x : XEXP (x, 0);
  5372.         case GEU:  case GTU:
  5373.           return unsignedp ? XEXP (x, 1) : x;
  5374.         case LEU:  case LTU:
  5375.           return unsignedp ? XEXP (x, 0) : x;
  5376.         }
  5377.         }
  5378.     }
  5379.     }
  5380.  
  5381.   fmt = GET_RTX_FORMAT (code);
  5382.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  5383.     {
  5384.       if (fmt[i] == 'e')
  5385.     SUBST (XEXP (x, i), known_cond (XEXP (x, i), cond, reg, val));
  5386.       else if (fmt[i] == 'E')
  5387.     for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  5388.       SUBST (XVECEXP (x, i, j), known_cond (XVECEXP (x, i, j),
  5389.                         cond, reg, val));
  5390.     }
  5391.  
  5392.   return x;
  5393. }
  5394.  
  5395. /* See if X, a SET operation, can be rewritten as a bit-field assignment.
  5396.    Return that assignment if so.
  5397.  
  5398.    We only handle the most common cases.  */
  5399.  
  5400. static rtx
  5401. make_field_assignment (x)
  5402.      rtx x;
  5403. {
  5404.   rtx dest = SET_DEST (x);
  5405.   rtx src = SET_SRC (x);
  5406.   rtx ourdest;
  5407.   rtx assign;
  5408.   HOST_WIDE_INT c1;
  5409.   int pos, len;
  5410.   rtx other;
  5411.   enum machine_mode mode;
  5412.  
  5413.   /* If SRC was (and (not (ashift (const_int 1) POS)) DEST), this is
  5414.      a clear of a one-bit field.  We will have changed it to
  5415.      (and (rotate (const_int -2) POS) DEST), so check for that.  Also check
  5416.      for a SUBREG.  */
  5417.  
  5418.   if (GET_CODE (src) == AND && GET_CODE (XEXP (src, 0)) == ROTATE
  5419.       && GET_CODE (XEXP (XEXP (src, 0), 0)) == CONST_INT
  5420.       && INTVAL (XEXP (XEXP (src, 0), 0)) == -2
  5421.       && (rtx_equal_p (dest, XEXP (src, 1))
  5422.       || rtx_equal_p (dest, get_last_value (XEXP (src, 1)))
  5423.       || rtx_equal_p (get_last_value (dest), XEXP (src, 1))))
  5424.     {
  5425.       assign = make_extraction (VOIDmode, dest, -1, XEXP (XEXP (src, 0), 1),
  5426.                 1, 1, 1, 0);
  5427.       return gen_rtx (SET, VOIDmode, assign, const0_rtx);
  5428.     }
  5429.  
  5430.   else if (GET_CODE (src) == AND && GET_CODE (XEXP (src, 0)) == SUBREG
  5431.        && subreg_lowpart_p (XEXP (src, 0))
  5432.        && (GET_MODE_SIZE (GET_MODE (XEXP (src, 0))) 
  5433.            < GET_MODE_SIZE (GET_MODE (SUBREG_REG (XEXP (src, 0)))))
  5434.        && GET_CODE (SUBREG_REG (XEXP (src, 0))) == ROTATE
  5435.        && INTVAL (XEXP (SUBREG_REG (XEXP (src, 0)), 0)) == -2
  5436.        && (rtx_equal_p (dest, XEXP (src, 1))
  5437.            || rtx_equal_p (dest, get_last_value (XEXP (src, 1)))
  5438.            || rtx_equal_p (get_last_value (dest), XEXP (src, 1))))
  5439.     {
  5440.       assign = make_extraction (VOIDmode, dest, -1,
  5441.                 XEXP (SUBREG_REG (XEXP (src, 0)), 1),
  5442.                 1, 1, 1, 0);
  5443.       return gen_rtx (SET, VOIDmode, assign, const0_rtx);
  5444.     }
  5445.  
  5446.   /* If SRC is (ior (ashift (const_int 1) POS DEST)), this is a set of a
  5447.      one-bit field.  */
  5448.   else if (GET_CODE (src) == IOR && GET_CODE (XEXP (src, 0)) == ASHIFT
  5449.        && XEXP (XEXP (src, 0), 0) == const1_rtx
  5450.        && (rtx_equal_p (dest, XEXP (src, 1))
  5451.            || rtx_equal_p (dest, get_last_value (XEXP (src, 1)))
  5452.            || rtx_equal_p (get_last_value (dest), XEXP (src, 1))))
  5453.     {
  5454.       assign = make_extraction (VOIDmode, dest, -1, XEXP (XEXP (src, 0), 1),
  5455.                 1, 1, 1, 0);
  5456.       return gen_rtx (SET, VOIDmode, assign, const1_rtx);
  5457.     }
  5458.  
  5459.   /* The other case we handle is assignments into a constant-position
  5460.      field.  They look like (ior (and DEST C1) OTHER).  If C1 represents
  5461.      a mask that has all one bits except for a group of zero bits and
  5462.      OTHER is known to have zeros where C1 has ones, this is such an
  5463.      assignment.  Compute the position and length from C1.  Shift OTHER
  5464.      to the appropriate position, force it to the required mode, and
  5465.      make the extraction.  Check for the AND in both operands.  */
  5466.  
  5467.   if (GET_CODE (src) == IOR && GET_CODE (XEXP (src, 0)) == AND
  5468.       && GET_CODE (XEXP (XEXP (src, 0), 1)) == CONST_INT
  5469.       && (rtx_equal_p (XEXP (XEXP (src, 0), 0), dest)
  5470.       || rtx_equal_p (XEXP (XEXP (src, 0), 0), get_last_value (dest))
  5471.       || rtx_equal_p (get_last_value (XEXP (XEXP (src, 0), 1)), dest)))
  5472.     c1 = INTVAL (XEXP (XEXP (src, 0), 1)), other = XEXP (src, 1);
  5473.   else if (GET_CODE (src) == IOR && GET_CODE (XEXP (src, 1)) == AND
  5474.        && GET_CODE (XEXP (XEXP (src, 1), 1)) == CONST_INT
  5475.        && (rtx_equal_p (XEXP (XEXP (src, 1), 0), dest)
  5476.            || rtx_equal_p (XEXP (XEXP (src, 1), 0), get_last_value (dest))
  5477.            || rtx_equal_p (get_last_value (XEXP (XEXP (src, 1), 0)),
  5478.                    dest)))
  5479.     c1 = INTVAL (XEXP (XEXP (src, 1), 1)), other = XEXP (src, 0);
  5480.   else
  5481.     return x;
  5482.  
  5483.   pos = get_pos_from_mask (~c1, &len);
  5484.   if (pos < 0 || pos + len > GET_MODE_BITSIZE (GET_MODE (dest))
  5485.       || (GET_MODE_BITSIZE (GET_MODE (other)) <= HOST_BITS_PER_WIDE_INT
  5486.       && (c1 & significant_bits (other, GET_MODE (other))) != 0))
  5487.     return x;
  5488.  
  5489.   assign = make_extraction (VOIDmode, dest, pos, NULL_RTX, len, 1, 1, 0);
  5490.  
  5491.   /* The mode to use for the source is the mode of the assignment, or of
  5492.      what is inside a possible STRICT_LOW_PART.  */
  5493.   mode = (GET_CODE (assign) == STRICT_LOW_PART 
  5494.       ? GET_MODE (XEXP (assign, 0)) : GET_MODE (assign));
  5495.  
  5496.   /* Shift OTHER right POS places and make it the source, restricting it
  5497.      to the proper length and mode.  */
  5498.  
  5499.   src = force_to_mode (simplify_shift_const (NULL_RTX, LSHIFTRT,
  5500.                          GET_MODE (src), other, pos),
  5501.                mode, len, dest);
  5502.  
  5503.   return gen_rtx_combine (SET, VOIDmode, assign, src);
  5504. }
  5505.  
  5506. /* See if X is of the form (+ (* a c) (* b c)) and convert to (* (+ a b) c)
  5507.    if so.  */
  5508.  
  5509. static rtx
  5510. apply_distributive_law (x)
  5511.      rtx x;
  5512. {
  5513.   enum rtx_code code = GET_CODE (x);
  5514.   rtx lhs, rhs, other;
  5515.   rtx tem;
  5516.   enum rtx_code inner_code;
  5517.  
  5518.   /* The outer operation can only be one of the following:  */
  5519.   if (code != IOR && code != AND && code != XOR
  5520.       && code != PLUS && code != MINUS)
  5521.     return x;
  5522.  
  5523.   lhs = XEXP (x, 0), rhs = XEXP (x, 1);
  5524.  
  5525.   /* If either operand is a primitive we can't do anything, so get out fast. */
  5526.   if (GET_RTX_CLASS (GET_CODE (lhs)) == 'o'
  5527.       || GET_RTX_CLASS (GET_CODE (rhs)) == 'o')
  5528.     return x;
  5529.  
  5530.   lhs = expand_compound_operation (lhs);
  5531.   rhs = expand_compound_operation (rhs);
  5532.   inner_code = GET_CODE (lhs);
  5533.   if (inner_code != GET_CODE (rhs))
  5534.     return x;
  5535.  
  5536.   /* See if the inner and outer operations distribute.  */
  5537.   switch (inner_code)
  5538.     {
  5539.     case LSHIFTRT:
  5540.     case ASHIFTRT:
  5541.     case AND:
  5542.     case IOR:
  5543.       /* These all distribute except over PLUS.  */
  5544.       if (code == PLUS || code == MINUS)
  5545.     return x;
  5546.       break;
  5547.  
  5548.     case MULT:
  5549.       if (code != PLUS && code != MINUS)
  5550.     return x;
  5551.       break;
  5552.  
  5553.     case ASHIFT:
  5554.     case LSHIFT:
  5555.       /* These are also multiplies, so they distribute over everything.  */
  5556.       break;
  5557.  
  5558.     case SUBREG:
  5559.       /* Non-paradoxical SUBREGs distributes over all operations, provided
  5560.      the inner modes and word numbers are the same, this is an extraction
  5561.      of a low-order part, we don't convert an fp operation to int or
  5562.      vice versa, and we would not be converting a single-word
  5563.      operation into a multi-word operation.  The latter test is not
  5564.      required, but it prevents generating unneeded multi-word operations.
  5565.      Some of the previous tests are redundant given the latter test, but
  5566.      are retained because they are required for correctness.
  5567.  
  5568.      We produce the result slightly differently in this case.  */
  5569.  
  5570.       if (GET_MODE (SUBREG_REG (lhs)) != GET_MODE (SUBREG_REG (rhs))
  5571.       || SUBREG_WORD (lhs) != SUBREG_WORD (rhs)
  5572.       || ! subreg_lowpart_p (lhs)
  5573.       || (GET_MODE_CLASS (GET_MODE (lhs))
  5574.           != GET_MODE_CLASS (GET_MODE (SUBREG_REG (lhs))))
  5575.       || (GET_MODE_SIZE (GET_MODE (lhs))
  5576.           < GET_MODE_SIZE (GET_MODE (SUBREG_REG (lhs))))
  5577.       || GET_MODE_SIZE (GET_MODE (SUBREG_REG (lhs))) > UNITS_PER_WORD)
  5578.     return x;
  5579.  
  5580.       tem = gen_binary (code, GET_MODE (SUBREG_REG (lhs)),
  5581.             SUBREG_REG (lhs), SUBREG_REG (rhs));
  5582.       return gen_lowpart_for_combine (GET_MODE (x), tem);
  5583.  
  5584.     default:
  5585.       return x;
  5586.     }
  5587.  
  5588.   /* Set LHS and RHS to the inner operands (A and B in the example
  5589.      above) and set OTHER to the common operand (C in the example).
  5590.      These is only one way to do this unless the inner operation is
  5591.      commutative.  */
  5592.   if (GET_RTX_CLASS (inner_code) == 'c'
  5593.       && rtx_equal_p (XEXP (lhs, 0), XEXP (rhs, 0)))
  5594.     other = XEXP (lhs, 0), lhs = XEXP (lhs, 1), rhs = XEXP (rhs, 1);
  5595.   else if (GET_RTX_CLASS (inner_code) == 'c'
  5596.        && rtx_equal_p (XEXP (lhs, 0), XEXP (rhs, 1)))
  5597.     other = XEXP (lhs, 0), lhs = XEXP (lhs, 1), rhs = XEXP (rhs, 0);
  5598.   else if (GET_RTX_CLASS (inner_code) == 'c'
  5599.        && rtx_equal_p (XEXP (lhs, 1), XEXP (rhs, 0)))
  5600.     other = XEXP (lhs, 1), lhs = XEXP (lhs, 0), rhs = XEXP (rhs, 1);
  5601.   else if (rtx_equal_p (XEXP (lhs, 1), XEXP (rhs, 1)))
  5602.     other = XEXP (lhs, 1), lhs = XEXP (lhs, 0), rhs = XEXP (rhs, 0);
  5603.   else
  5604.     return x;
  5605.  
  5606.   /* Form the new inner operation, seeing if it simplifies first.  */
  5607.   tem = gen_binary (code, GET_MODE (x), lhs, rhs);
  5608.  
  5609.   /* There is one exception to the general way of distributing:
  5610.      (a ^ b) | (a ^ c) -> (~a) & (b ^ c)  */
  5611.   if (code == XOR && inner_code == IOR)
  5612.     {
  5613.       inner_code = AND;
  5614.       other = gen_unary (NOT, GET_MODE (x), other);
  5615.     }
  5616.  
  5617.   /* We may be able to continuing distributing the result, so call
  5618.      ourselves recursively on the inner operation before forming the
  5619.      outer operation, which we return.  */
  5620.   return gen_binary (inner_code, GET_MODE (x),
  5621.              apply_distributive_law (tem), other);
  5622. }
  5623.  
  5624. /* We have X, a logical `and' of VAROP with the constant CONSTOP, to be done
  5625.    in MODE.
  5626.  
  5627.    Return an equivalent form, if different from X.  Otherwise, return X.  If
  5628.    X is zero, we are to always construct the equivalent form.  */
  5629.  
  5630. static rtx
  5631. simplify_and_const_int (x, mode, varop, constop)
  5632.      rtx x;
  5633.      enum machine_mode mode;
  5634.      rtx varop;
  5635.      unsigned HOST_WIDE_INT constop;
  5636. {
  5637.   register enum machine_mode tmode;
  5638.   register rtx temp;
  5639.   unsigned HOST_WIDE_INT significant;
  5640.  
  5641.   /* There is a large class of optimizations based on the principle that
  5642.      some operations produce results where certain bits are known to be zero,
  5643.      and hence are not significant to the AND.  For example, if we have just
  5644.      done a left shift of one bit, the low-order bit is known to be zero and
  5645.      hence an AND with a mask of ~1 would not do anything.
  5646.  
  5647.      At the end of the following loop, we set:
  5648.  
  5649.      VAROP to be the item to be AND'ed with;
  5650.      CONSTOP to the constant value to AND it with.  */
  5651.  
  5652.   while (1)
  5653.     {
  5654.       /* If we ever encounter a mode wider than the host machine's widest
  5655.      integer size, we can't compute the masks accurately, so give up.  */
  5656.       if (GET_MODE_BITSIZE (GET_MODE (varop)) > HOST_BITS_PER_WIDE_INT)
  5657.     break;
  5658.  
  5659.       /* Unless one of the cases below does a `continue',
  5660.      a `break' will be executed to exit the loop.  */
  5661.  
  5662.       switch (GET_CODE (varop))
  5663.     {
  5664.     case CLOBBER:
  5665.       /* If VAROP is a (clobber (const_int)), return it since we know
  5666.          we are generating something that won't match. */
  5667.       return varop;
  5668.  
  5669. #if ! BITS_BIG_ENDIAN
  5670.     case USE:
  5671.       /* VAROP is a (use (mem ..)) that was made from a bit-field
  5672.          extraction that spanned the boundary of the MEM.  If we are
  5673.          now masking so it is within that boundary, we don't need the
  5674.          USE any more.  */
  5675.       if ((constop & ~ GET_MODE_MASK (GET_MODE (XEXP (varop, 0)))) == 0)
  5676.         {
  5677.           varop = XEXP (varop, 0);
  5678.           continue;
  5679.         }
  5680.       break;
  5681. #endif
  5682.  
  5683.     case SUBREG:
  5684.       if (subreg_lowpart_p (varop)
  5685.           /* We can ignore the effect this SUBREG if it narrows the mode
  5686.          or, on machines where byte operations extend, if the
  5687.          constant masks to zero all the bits the mode doesn't have.  */
  5688.           && ((GET_MODE_SIZE (GET_MODE (varop))
  5689.            < GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop))))
  5690. #if defined(BYTE_LOADS_ZERO_EXTEND) || defined(BYTE_LOADS_SIGN_EXTEND)
  5691.           || (0 == (constop
  5692.                 & GET_MODE_MASK (GET_MODE (varop))
  5693.                 & ~ GET_MODE_MASK (GET_MODE (SUBREG_REG (varop)))))
  5694. #endif
  5695.           ))
  5696.         {
  5697.           varop = SUBREG_REG (varop);
  5698.           continue;
  5699.         }
  5700.       break;
  5701.  
  5702.     case ZERO_EXTRACT:
  5703.     case SIGN_EXTRACT:
  5704.     case ZERO_EXTEND:
  5705.     case SIGN_EXTEND:
  5706.       /* Try to expand these into a series of shifts and then work
  5707.          with that result.  If we can't, for example, if the extract
  5708.          isn't at a fixed position, give up.  */
  5709.       temp = expand_compound_operation (varop);
  5710.       if (temp != varop)
  5711.         {
  5712.           varop = temp;
  5713.           continue;
  5714.         }
  5715.       break;
  5716.  
  5717.     case AND:
  5718.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT)
  5719.         {
  5720.           constop &= INTVAL (XEXP (varop, 1));
  5721.           varop = XEXP (varop, 0);
  5722.           continue;
  5723.         }
  5724.       break;
  5725.  
  5726.     case IOR:
  5727.     case XOR:
  5728.       /* If VAROP is (ior (lshiftrt FOO C1) C2), try to commute the IOR and
  5729.          LSHIFT so we end up with an (and (lshiftrt (ior ...) ...) ...)
  5730.          operation which may be a bitfield extraction.  */
  5731.  
  5732.       if (GET_CODE (XEXP (varop, 0)) == LSHIFTRT
  5733.           && GET_CODE (XEXP (XEXP (varop, 0), 1)) == CONST_INT
  5734.           && INTVAL (XEXP (XEXP (varop, 0), 1)) >= 0
  5735.           && INTVAL (XEXP (XEXP (varop, 0), 1)) < HOST_BITS_PER_WIDE_INT
  5736.           && GET_CODE (XEXP (varop, 1)) == CONST_INT
  5737.           && (INTVAL (XEXP (varop, 1))
  5738.           & ~ significant_bits (XEXP (varop, 0),
  5739.                     GET_MODE (varop)) == 0))
  5740.         {
  5741.           temp = GEN_INT ((INTVAL (XEXP (varop, 1)) & constop)
  5742.                   << INTVAL (XEXP (XEXP (varop, 0), 1)));
  5743.           temp = gen_binary (GET_CODE (varop), GET_MODE (varop),
  5744.                  XEXP (XEXP (varop, 0), 0), temp);
  5745.           varop = gen_rtx_combine (LSHIFTRT, GET_MODE (varop),
  5746.                        temp, XEXP (varop, 1));
  5747.           continue;
  5748.         }
  5749.  
  5750.       /* Apply the AND to both branches of the IOR or XOR, then try to
  5751.          apply the distributive law.  This may eliminate operations 
  5752.          if either branch can be simplified because of the AND.
  5753.          It may also make some cases more complex, but those cases
  5754.          probably won't match a pattern either with or without this.  */
  5755.       return 
  5756.         gen_lowpart_for_combine
  5757.           (mode, apply_distributive_law
  5758.            (gen_rtx_combine
  5759.         (GET_CODE (varop), GET_MODE (varop),
  5760.          simplify_and_const_int (NULL_RTX, GET_MODE (varop),
  5761.                      XEXP (varop, 0), constop),
  5762.          simplify_and_const_int (NULL_RTX, GET_MODE (varop),
  5763.                      XEXP (varop, 1), constop))));
  5764.  
  5765.     case NOT:
  5766.       /* (and (not FOO)) is (and (xor FOO CONST_OP)) so if FOO is an
  5767.          LSHIFTRT we can do the same as above.  */
  5768.  
  5769.       if (GET_CODE (XEXP (varop, 0)) == LSHIFTRT
  5770.           && GET_CODE (XEXP (XEXP (varop, 0), 1)) == CONST_INT
  5771.           && INTVAL (XEXP (XEXP (varop, 0), 1)) >= 0
  5772.           && INTVAL (XEXP (XEXP (varop, 0), 1)) < HOST_BITS_PER_WIDE_INT)
  5773.         {
  5774.           temp = GEN_INT (constop << INTVAL (XEXP (XEXP (varop, 0), 1)));
  5775.           temp = gen_binary (XOR, GET_MODE (varop),
  5776.                  XEXP (XEXP (varop, 0), 0), temp);
  5777.           varop = gen_rtx_combine (LSHIFTRT, GET_MODE (varop),
  5778.                        temp, XEXP (XEXP (varop, 0), 1));
  5779.           continue;
  5780.         }
  5781.       break;
  5782.  
  5783.     case ASHIFTRT:
  5784.       /* If we are just looking for the sign bit, we don't need this
  5785.          shift at all, even if it has a variable count.  */
  5786.       if (constop == ((HOST_WIDE_INT) 1
  5787.               << (GET_MODE_BITSIZE (GET_MODE (varop)) - 1)))
  5788.         {
  5789.           varop = XEXP (varop, 0);
  5790.           continue;
  5791.         }
  5792.  
  5793.       /* If this is a shift by a constant, get a mask that contains
  5794.          those bits that are not copies of the sign bit.  We then have
  5795.          two cases:  If CONSTOP only includes those bits, this can be
  5796.          a logical shift, which may allow simplifications.  If CONSTOP
  5797.          is a single-bit field not within those bits, we are requesting
  5798.          a copy of the sign bit and hence can shift the sign bit to
  5799.          the appropriate location.  */
  5800.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT
  5801.           && INTVAL (XEXP (varop, 1)) >= 0
  5802.           && INTVAL (XEXP (varop, 1)) < HOST_BITS_PER_WIDE_INT)
  5803.         {
  5804.           int i = -1;
  5805.  
  5806.           significant = GET_MODE_MASK (GET_MODE (varop));
  5807.           significant >>= INTVAL (XEXP (varop, 1));
  5808.  
  5809.           if ((constop & ~significant) == 0
  5810.           || (i = exact_log2 (constop)) >= 0)
  5811.         {
  5812.           varop = simplify_shift_const
  5813.             (varop, LSHIFTRT, GET_MODE (varop), XEXP (varop, 0),
  5814.              i < 0 ? INTVAL (XEXP (varop, 1))
  5815.              : GET_MODE_BITSIZE (GET_MODE (varop)) - 1 - i);
  5816.           if (GET_CODE (varop) != ASHIFTRT)
  5817.             continue;
  5818.         }
  5819.         }
  5820.  
  5821.       /* If our mask is 1, convert this to a LSHIFTRT.  This can be done
  5822.          even if the shift count isn't a constant.  */
  5823.       if (constop == 1)
  5824.         varop = gen_rtx_combine (LSHIFTRT, GET_MODE (varop),
  5825.                      XEXP (varop, 0), XEXP (varop, 1));
  5826.       break;
  5827.  
  5828.     case NE:
  5829.       /* (and (ne FOO 0) CONST) can be (and FOO CONST) if CONST is
  5830.          included in STORE_FLAG_VALUE and FOO has no significant bits
  5831.          not in CONST.  */
  5832.       if ((constop & ~ STORE_FLAG_VALUE) == 0
  5833.           && XEXP (varop, 0) == const0_rtx
  5834.           && (significant_bits (XEXP (varop, 0), mode) & ~ constop) == 0)
  5835.         {
  5836.           varop = XEXP (varop, 0);
  5837.           continue;
  5838.         }
  5839.       break;
  5840.  
  5841.     case PLUS:
  5842.       /* In (and (plus FOO C1) M), if M is a mask that just turns off
  5843.          low-order bits (as in an alignment operation) and FOO is already
  5844.          aligned to that boundary, we can convert remove this AND
  5845.          and possibly the PLUS if it is now adding zero.  */
  5846.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT
  5847.           && exact_log2 (-constop) >= 0
  5848.           && (significant_bits (XEXP (varop, 0), mode) & ~ constop) == 0)
  5849.         {
  5850.           varop = plus_constant (XEXP (varop, 0),
  5851.                      INTVAL (XEXP (varop, 1)) & constop);
  5852.           constop = ~0;
  5853.           break;
  5854.         }
  5855.  
  5856.       /* ... fall through ... */
  5857.  
  5858.     case MINUS:
  5859.       /* In (and (plus (and FOO M1) BAR) M2), if M1 and M2 are one
  5860.          less than powers of two and M2 is narrower than M1, we can
  5861.          eliminate the inner AND.  This occurs when incrementing
  5862.          bit fields.  */
  5863.  
  5864.       if (GET_CODE (XEXP (varop, 0)) == ZERO_EXTRACT
  5865.           || GET_CODE (XEXP (varop, 0)) == ZERO_EXTEND)
  5866.         SUBST (XEXP (varop, 0),
  5867.            expand_compound_operation (XEXP (varop, 0)));
  5868.  
  5869.       if (GET_CODE (XEXP (varop, 0)) == AND
  5870.           && GET_CODE (XEXP (XEXP (varop, 0), 1)) == CONST_INT
  5871.           && exact_log2 (constop + 1) >= 0
  5872.           && exact_log2 (INTVAL (XEXP (XEXP (varop, 0), 1)) + 1) >= 0
  5873.           && (~ INTVAL (XEXP (XEXP (varop, 0), 1)) & constop) == 0)
  5874.         SUBST (XEXP (varop, 0), XEXP (XEXP (varop, 0), 0));
  5875.       break;
  5876.     }
  5877.  
  5878.       break;
  5879.     }
  5880.  
  5881.   /* If we have reached a constant, this whole thing is constant.  */
  5882.   if (GET_CODE (varop) == CONST_INT)
  5883.     return GEN_INT (constop & INTVAL (varop));
  5884.  
  5885.   /* See what bits are significant in VAROP.  */
  5886.   significant = significant_bits (varop, mode);
  5887.  
  5888.   /* Turn off all bits in the constant that are known to already be zero.
  5889.      Thus, if the AND isn't needed at all, we will have CONSTOP == SIGNIFICANT
  5890.      which is tested below.  */
  5891.  
  5892.   constop &= significant;
  5893.  
  5894.   /* If we don't have any bits left, return zero.  */
  5895.   if (constop == 0)
  5896.     return const0_rtx;
  5897.  
  5898.   /* Get VAROP in MODE.  Try to get a SUBREG if not.  Don't make a new SUBREG
  5899.      if we already had one (just check for the simplest cases).  */
  5900.   if (x && GET_CODE (XEXP (x, 0)) == SUBREG
  5901.       && GET_MODE (XEXP (x, 0)) == mode
  5902.       && SUBREG_REG (XEXP (x, 0)) == varop)
  5903.     varop = XEXP (x, 0);
  5904.   else
  5905.     varop = gen_lowpart_for_combine (mode, varop);
  5906.  
  5907.   /* If we can't make the SUBREG, try to return what we were given. */
  5908.   if (GET_CODE (varop) == CLOBBER)
  5909.     return x ? x : varop;
  5910.  
  5911.   /* If we are only masking insignificant bits, return VAROP.  */
  5912.   if (constop == significant)
  5913.     x = varop;
  5914.  
  5915.   /* Otherwise, return an AND.  See how much, if any, of X we can use.  */
  5916.   else if (x == 0 || GET_CODE (x) != AND || GET_MODE (x) != mode)
  5917.     x = gen_rtx_combine (AND, mode, varop, GEN_INT (constop));
  5918.  
  5919.   else
  5920.     {
  5921.       if (GET_CODE (XEXP (x, 1)) != CONST_INT
  5922.       || INTVAL (XEXP (x, 1)) != constop)
  5923.     SUBST (XEXP (x, 1), GEN_INT (constop));
  5924.  
  5925.       SUBST (XEXP (x, 0), varop);
  5926.     }
  5927.  
  5928.   return x;
  5929. }
  5930.  
  5931. /* Given an expression, X, compute which bits in X can be non-zero.
  5932.    We don't care about bits outside of those defined in MODE.
  5933.  
  5934.    For most X this is simply GET_MODE_MASK (GET_MODE (MODE)), but if X is
  5935.    a shift, AND, or zero_extract, we can do better.  */
  5936.  
  5937. static unsigned HOST_WIDE_INT
  5938. significant_bits (x, mode)
  5939.      rtx x;
  5940.      enum machine_mode mode;
  5941. {
  5942.   unsigned HOST_WIDE_INT significant = GET_MODE_MASK (mode);
  5943.   unsigned HOST_WIDE_INT inner_sig;
  5944.   enum rtx_code code;
  5945.   int mode_width = GET_MODE_BITSIZE (mode);
  5946.   rtx tem;
  5947.  
  5948.   /* If X is wider than MODE, use its mode instead.  */
  5949.   if (GET_MODE_BITSIZE (GET_MODE (x)) > mode_width)
  5950.     {
  5951.       mode = GET_MODE (x);
  5952.       significant = GET_MODE_MASK (mode);
  5953.       mode_width = GET_MODE_BITSIZE (mode);
  5954.     }
  5955.  
  5956.   if (mode_width > HOST_BITS_PER_WIDE_INT)
  5957.     /* Our only callers in this case look for single bit values.  So
  5958.        just return the mode mask.  Those tests will then be false.  */
  5959.     return significant;
  5960.  
  5961.   code = GET_CODE (x);
  5962.   switch (code)
  5963.     {
  5964.     case REG:
  5965. #ifdef STACK_BOUNDARY
  5966.       /* If this is the stack pointer, we may know something about its
  5967.      alignment.  If PUSH_ROUNDING is defined, it is possible for the
  5968.      stack to be momentarily aligned only to that amount, so we pick
  5969.      the least alignment.  */
  5970.  
  5971.       if (x == stack_pointer_rtx)
  5972.     {
  5973.       int sp_alignment = STACK_BOUNDARY / BITS_PER_UNIT;
  5974.  
  5975. #ifdef PUSH_ROUNDING
  5976.       sp_alignment = MIN (PUSH_ROUNDING (1), sp_alignment);
  5977. #endif
  5978.  
  5979.       return significant & ~ (sp_alignment - 1);
  5980.     }
  5981. #endif
  5982.  
  5983.       /* If X is a register whose value we can find, use that value.  
  5984.      Otherwise, use the previously-computed significant bits for this
  5985.      register.  */
  5986.  
  5987.       tem = get_last_value (x);
  5988.       if (tem)
  5989.     return significant_bits (tem, mode);
  5990.       else if (significant_valid && reg_significant[REGNO (x)])
  5991.     return reg_significant[REGNO (x)] & significant;
  5992.       else
  5993.     return significant;
  5994.  
  5995.     case CONST_INT:
  5996.       return INTVAL (x);
  5997.  
  5998. #ifdef BYTE_LOADS_ZERO_EXTEND
  5999.     case MEM:
  6000.       /* In many, if not most, RISC machines, reading a byte from memory
  6001.      zeros the rest of the register.  Noticing that fact saves a lot
  6002.      of extra zero-extends.  */
  6003.       significant &= GET_MODE_MASK (GET_MODE (x));
  6004.       break;
  6005. #endif
  6006.  
  6007. #if STORE_FLAG_VALUE == 1
  6008.     case EQ:  case NE:
  6009.     case GT:  case GTU:
  6010.     case LT:  case LTU:
  6011.     case GE:  case GEU:
  6012.     case LE:  case LEU:
  6013.  
  6014.       if (GET_MODE_CLASS (mode) == MODE_INT)
  6015.     significant = 1;
  6016.  
  6017.       /* A comparison operation only sets the bits given by its mode.  The
  6018.      rest are set undefined.  */
  6019.       if (GET_MODE_SIZE (GET_MODE (x)) < mode_width)
  6020.     significant |= (GET_MODE_MASK (mode) & ~ GET_MODE_MASK (GET_MODE (x)));
  6021.       break;
  6022. #endif
  6023.  
  6024.     case NEG:
  6025.       if (num_sign_bit_copies (XEXP (x, 0), GET_MODE (x))
  6026.       == GET_MODE_BITSIZE (GET_MODE (x)))
  6027.     significant = 1;
  6028.  
  6029.       if (GET_MODE_SIZE (GET_MODE (x)) < mode_width)
  6030.     significant |= (GET_MODE_MASK (mode) & ~ GET_MODE_MASK (GET_MODE (x)));
  6031.       break;
  6032.  
  6033.     case ABS:
  6034.       if (num_sign_bit_copies (XEXP (x, 0), GET_MODE (x))
  6035.       == GET_MODE_BITSIZE (GET_MODE (x)))
  6036.     significant = 1;
  6037.       break;
  6038.  
  6039.     case TRUNCATE:
  6040.       significant &= (significant_bits (XEXP (x, 0), mode)
  6041.               & GET_MODE_MASK (mode));
  6042.       break;
  6043.  
  6044.     case ZERO_EXTEND:
  6045.       significant &= significant_bits (XEXP (x, 0), mode);
  6046.       if (GET_MODE (XEXP (x, 0)) != VOIDmode)
  6047.     significant &= GET_MODE_MASK (GET_MODE (XEXP (x, 0)));
  6048.       break;
  6049.  
  6050.     case SIGN_EXTEND:
  6051.       /* If the sign bit is known clear, this is the same as ZERO_EXTEND.
  6052.      Otherwise, show all the bits in the outer mode but not the inner
  6053.      may be non-zero.  */
  6054.       inner_sig = significant_bits (XEXP (x, 0), mode);
  6055.       if (GET_MODE (XEXP (x, 0)) != VOIDmode)
  6056.     {
  6057.       inner_sig &= GET_MODE_MASK (GET_MODE (XEXP (x, 0)));
  6058.       if (inner_sig &
  6059.           (((HOST_WIDE_INT) 1
  6060.         << (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - 1))))
  6061.         inner_sig |= (GET_MODE_MASK (mode)
  6062.               & ~ GET_MODE_MASK (GET_MODE (XEXP (x, 0))));
  6063.     }
  6064.  
  6065.       significant &= inner_sig;
  6066.       break;
  6067.  
  6068.     case AND:
  6069.       significant &= (significant_bits (XEXP (x, 0), mode)
  6070.               & significant_bits (XEXP (x, 1), mode));
  6071.       break;
  6072.  
  6073.     case XOR:   case IOR:
  6074.     case UMIN:  case UMAX:  case SMIN:  case SMAX:
  6075.       significant &= (significant_bits (XEXP (x, 0), mode)
  6076.               | significant_bits (XEXP (x, 1), mode));
  6077.       break;
  6078.  
  6079.     case PLUS:  case MINUS:
  6080.     case MULT:
  6081.     case DIV:   case UDIV:
  6082.     case MOD:   case UMOD:
  6083.       /* We can apply the rules of arithmetic to compute the number of
  6084.      high- and low-order zero bits of these operations.  We start by
  6085.      computing the width (position of the highest-order non-zero bit)
  6086.      and the number of low-order zero bits for each value.  */
  6087.       {
  6088.     unsigned HOST_WIDE_INT sig0 = significant_bits (XEXP (x, 0), mode);
  6089.     unsigned HOST_WIDE_INT sig1 = significant_bits (XEXP (x, 1), mode);
  6090.     int width0 = floor_log2 (sig0) + 1;
  6091.     int width1 = floor_log2 (sig1) + 1;
  6092.     int low0 = floor_log2 (sig0 & -sig0);
  6093.     int low1 = floor_log2 (sig1 & -sig1);
  6094.     int op0_maybe_minusp = (sig0 & (1 << (mode_width - 1)));
  6095.     int op1_maybe_minusp = (sig1 & (1 << (mode_width - 1)));
  6096.     int result_width = mode_width;
  6097.     int result_low = 0;
  6098.  
  6099.     switch (code)
  6100.       {
  6101.       case PLUS:
  6102.         result_width = MAX (width0, width1) + 1;
  6103.         result_low = MIN (low0, low1);
  6104.         break;
  6105.       case MINUS:
  6106.         result_low = MIN (low0, low1);
  6107.         break;
  6108.       case MULT:
  6109.         result_width = width0 + width1;
  6110.         result_low = low0 + low1;
  6111.         break;
  6112.       case DIV:
  6113.         if (! op0_maybe_minusp && ! op1_maybe_minusp)
  6114.           result_width = width0;
  6115.         break;
  6116.       case UDIV:
  6117.         result_width = width0;
  6118.         break;
  6119.       case MOD:
  6120.         if (! op0_maybe_minusp && ! op1_maybe_minusp)
  6121.           result_width = MIN (width0, width1);
  6122.         result_low = MIN (low0, low1);
  6123.         break;
  6124.       case UMOD:
  6125.         result_width = MIN (width0, width1);
  6126.         result_low = MIN (low0, low1);
  6127.         break;
  6128.       }
  6129.  
  6130.     if (result_width < mode_width)
  6131.       significant &= ((HOST_WIDE_INT) 1 << result_width) - 1;
  6132.  
  6133.     if (result_low > 0)
  6134.       significant &= ~ (((HOST_WIDE_INT) 1 << result_low) - 1);
  6135.       }
  6136.       break;
  6137.  
  6138.     case ZERO_EXTRACT:
  6139.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  6140.       && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT)
  6141.     significant &= ((HOST_WIDE_INT) 1 << INTVAL (XEXP (x, 1))) - 1;
  6142.       break;
  6143.  
  6144.     case SUBREG:
  6145.       /* If this is a SUBREG formed for a promoted variable that has
  6146.      been zero-extended, we know that at least the high-order bits
  6147.      are zero, though others might be too.  */
  6148.  
  6149.       if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_UNSIGNED_P (x))
  6150.     significant = (GET_MODE_MASK (GET_MODE (x))
  6151.                & significant_bits (SUBREG_REG (x), GET_MODE (x)));
  6152.  
  6153.       /* If the inner mode is a single word for both the host and target
  6154.      machines, we can compute this from which bits of the inner
  6155.      object are known significant.  */
  6156.       if (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))) <= BITS_PER_WORD
  6157.       && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))
  6158.           <= HOST_BITS_PER_WIDE_INT))
  6159.     {
  6160.       significant &= significant_bits (SUBREG_REG (x), mode);
  6161. #if ! defined(BYTE_LOADS_ZERO_EXTEND) && ! defined(BYTE_LOADS_SIGN_EXTEND)
  6162.       /* On many CISC machines, accessing an object in a wider mode
  6163.          causes the high-order bits to become undefined.  So they are
  6164.          not known to be zero.  */
  6165.       if (GET_MODE_SIZE (GET_MODE (x))
  6166.           > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  6167.         significant |= (GET_MODE_MASK (GET_MODE (x))
  6168.                 & ~ GET_MODE_MASK (GET_MODE (SUBREG_REG (x))));
  6169. #endif
  6170.     }
  6171.       break;
  6172.  
  6173.     case ASHIFTRT:
  6174.     case LSHIFTRT:
  6175.     case ASHIFT:
  6176.     case LSHIFT:
  6177.     case ROTATE:
  6178.       /* The significant bits are in two classes: any bits within MODE
  6179.      that aren't in GET_MODE (x) are always significant.  The rest of the
  6180.      significant bits are those that are significant in the operand of
  6181.      the shift when shifted the appropriate number of bits.  This
  6182.      shows that high-order bits are cleared by the right shift and
  6183.      low-order bits by left shifts.  */
  6184.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  6185.       && INTVAL (XEXP (x, 1)) >= 0
  6186.       && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT)
  6187.     {
  6188.       enum machine_mode inner_mode = GET_MODE (x);
  6189.       int width = GET_MODE_BITSIZE (inner_mode);
  6190.       int count = INTVAL (XEXP (x, 1));
  6191.       unsigned HOST_WIDE_INT mode_mask = GET_MODE_MASK (inner_mode);
  6192.       unsigned HOST_WIDE_INT op_significant
  6193.         = significant_bits (XEXP (x, 0), mode);
  6194.       unsigned HOST_WIDE_INT inner = op_significant & mode_mask;
  6195.       unsigned HOST_WIDE_INT outer = 0;
  6196.  
  6197.       if (mode_width > width)
  6198.         outer = (op_significant & significant & ~ mode_mask);
  6199.  
  6200.       if (code == LSHIFTRT)
  6201.         inner >>= count;
  6202.       else if (code == ASHIFTRT)
  6203.         {
  6204.           inner >>= count;
  6205.  
  6206.           /* If the sign bit was significant at before the shift, we
  6207.          need to mark all the places it could have been copied to
  6208.          by the shift significant.  */
  6209.           if (inner & ((HOST_WIDE_INT) 1 << (width - 1 - count)))
  6210.         inner |= (((HOST_WIDE_INT) 1 << count) - 1) << (width - count);
  6211.         }
  6212.       else if (code == LSHIFT || code == ASHIFT)
  6213.         inner <<= count;
  6214.       else
  6215.         inner = ((inner << (count % width)
  6216.               | (inner >> (width - (count % width)))) & mode_mask);
  6217.  
  6218.       significant &= (outer | inner);
  6219.     }
  6220.       break;
  6221.  
  6222.     case FFS:
  6223.       /* This is at most the number of bits in the mode.  */
  6224.       significant = ((HOST_WIDE_INT) 1 << (floor_log2 (mode_width) + 1)) - 1;
  6225.       break;
  6226.  
  6227.     case IF_THEN_ELSE:
  6228.       significant &= (significant_bits (XEXP (x, 1), mode)
  6229.               | significant_bits (XEXP (x, 2), mode));
  6230.       break;
  6231.     }
  6232.  
  6233.   return significant;
  6234. }
  6235.  
  6236. /* Return the number of bits at the high-order end of X that are known to
  6237.    be equal to the sign bit.  This number will always be between 1 and
  6238.    the number of bits in the mode of X.  MODE is the mode to be used
  6239.    if X is VOIDmode.  */
  6240.  
  6241. static int
  6242. num_sign_bit_copies (x, mode)
  6243.      rtx x;
  6244.      enum machine_mode mode;
  6245. {
  6246.   enum rtx_code code = GET_CODE (x);
  6247.   int bitwidth;
  6248.   int num0, num1, result;
  6249.   unsigned HOST_WIDE_INT sig;
  6250.   rtx tem;
  6251.  
  6252.   /* If we weren't given a mode, use the mode of X.  If the mode is still
  6253.      VOIDmode, we don't know anything.  */
  6254.  
  6255.   if (mode == VOIDmode)
  6256.     mode = GET_MODE (x);
  6257.  
  6258.   if (mode == VOIDmode)
  6259.     return 1;
  6260.  
  6261.   bitwidth = GET_MODE_BITSIZE (mode);
  6262.  
  6263.   switch (code)
  6264.     {
  6265.     case REG:
  6266.       if (significant_valid && reg_sign_bit_copies[REGNO (x)] != 0)
  6267.     return reg_sign_bit_copies[REGNO (x)];
  6268.  
  6269.       tem =  get_last_value (x);
  6270.       if (tem != 0)
  6271.     return num_sign_bit_copies (tem, mode);
  6272.       break;
  6273.  
  6274. #ifdef BYTE_LOADS_SIGN_EXTEND
  6275.     case MEM:
  6276.       /* Some RISC machines sign-extend all loads of smaller than a word.  */
  6277.       return MAX (1, bitwidth - GET_MODE_BITSIZE (GET_MODE (x)) + 1);
  6278. #endif
  6279.  
  6280.     case CONST_INT:
  6281.       /* If the constant is negative, take its 1's complement and remask.
  6282.      Then see how many zero bits we have.  */
  6283.       sig = INTVAL (x) & GET_MODE_MASK (mode);
  6284.       if (bitwidth <= HOST_BITS_PER_WIDE_INT
  6285.       && (sig & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  6286.     sig = (~ sig) & GET_MODE_MASK (mode);
  6287.  
  6288.       return (sig == 0 ? bitwidth : bitwidth - floor_log2 (sig) - 1);
  6289.  
  6290.     case SUBREG:
  6291.       /* If this is a SUBREG for a promoted object that is sign-extended
  6292.      and we are looking at it in a wider mode, we know that at least the
  6293.      high-order bits are known to be sign bit copies.  */
  6294.  
  6295.       if (SUBREG_PROMOTED_VAR_P (x) && ! SUBREG_PROMOTED_UNSIGNED_P (x))
  6296.     return (GET_MODE_BITSIZE (mode) - GET_MODE_BITSIZE (GET_MODE (x))
  6297.         + num_sign_bit_copies (SUBREG_REG (x), GET_MODE (x)));
  6298.  
  6299.       /* For a smaller object, just ignore the high bits. */
  6300.       if (bitwidth <= GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))))
  6301.     {
  6302.       num0 = num_sign_bit_copies (SUBREG_REG (x), VOIDmode);
  6303.       return MAX (1, (num0
  6304.               - (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))
  6305.                  - bitwidth)));
  6306.     }
  6307.  
  6308. #if defined(BYTE_LOADS_ZERO_EXTEND) || defined(BYTE_LOADS_SIGN_EXTEND)
  6309.       /* For paradoxical SUBREGs, just look inside since, on machines with
  6310.      one of these defined, we assume that operations are actually 
  6311.      performed on the full register.  Note that we are passing MODE
  6312.      to the recursive call, so the number of sign bit copies will
  6313.      remain relative to that mode, not the inner mode.  */
  6314.  
  6315.       if (GET_MODE_SIZE (GET_MODE (x))
  6316.       > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  6317.     return num_sign_bit_copies (SUBREG_REG (x), mode);
  6318. #endif
  6319.  
  6320.       break;
  6321.  
  6322.     case SIGN_EXTRACT:
  6323.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  6324.     return MAX (1, bitwidth - INTVAL (XEXP (x, 1)));
  6325.       break;
  6326.  
  6327.     case SIGN_EXTEND: 
  6328.       return (bitwidth - GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))
  6329.           + num_sign_bit_copies (XEXP (x, 0), VOIDmode));
  6330.  
  6331.     case TRUNCATE:
  6332.       /* For a smaller object, just ignore the high bits. */
  6333.       num0 = num_sign_bit_copies (XEXP (x, 0), VOIDmode);
  6334.       return MAX (1, (num0 - (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))
  6335.                   - bitwidth)));
  6336.  
  6337.     case NOT:
  6338.       return num_sign_bit_copies (XEXP (x, 0), mode);
  6339.  
  6340.     case ROTATE:       case ROTATERT:
  6341.       /* If we are rotating left by a number of bits less than the number
  6342.      of sign bit copies, we can just subtract that amount from the
  6343.      number.  */
  6344.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  6345.       && INTVAL (XEXP (x, 1)) >= 0 && INTVAL (XEXP (x, 1)) < bitwidth)
  6346.     {
  6347.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  6348.       return MAX (1, num0 - (code == ROTATE ? INTVAL (XEXP (x, 1))
  6349.                  : bitwidth - INTVAL (XEXP (x, 1))));
  6350.     }
  6351.       break;
  6352.  
  6353.     case NEG:
  6354.       /* In general, this subtracts one sign bit copy.  But if the value
  6355.      is known to be positive, the number of sign bit copies is the
  6356.      same as that of the input.  Finally, if the input has just one
  6357.      significant bit, all the bits are copies of the sign bit.  */
  6358.       sig = significant_bits (XEXP (x, 0), mode);
  6359.       if (sig == 1)
  6360.     return bitwidth;
  6361.  
  6362.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  6363.       if (num0 > 1
  6364.       && bitwidth <= HOST_BITS_PER_WIDE_INT
  6365.       && (((HOST_WIDE_INT) 1 << (bitwidth - 1)) & sig))
  6366.     num0--;
  6367.  
  6368.       return num0;
  6369.  
  6370.     case IOR:   case AND:   case XOR:
  6371.     case SMIN:  case SMAX:  case UMIN:  case UMAX:
  6372.       /* Logical operations will preserve the number of sign-bit copies.
  6373.      MIN and MAX operations always return one of the operands.  */
  6374.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  6375.       num1 = num_sign_bit_copies (XEXP (x, 1), mode);
  6376.       return MIN (num0, num1);
  6377.  
  6378.     case PLUS:  case MINUS:
  6379.       /* For addition and subtraction, we can have a 1-bit carry.  However,
  6380.      if we are subtracting 1 from a positive number, there will not
  6381.      be such a carry.  Furthermore, if the positive number is known to
  6382.      be 0 or 1, we know the result is either -1 or 0.  */
  6383.  
  6384.       if (code == PLUS && XEXP (x, 1) == constm1_rtx
  6385.       /* Don't do this if XEXP (x, 0) is a paradoxical subreg
  6386.          because in principle we don't know what the high bits are.  */
  6387.       && !(GET_CODE (XEXP (x, 0)) == SUBREG
  6388.            && (GET_MODE_SIZE (GET_MODE (XEXP (XEXP (x, 0), 0)))
  6389.            < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))))
  6390.     {
  6391.       sig = significant_bits (XEXP (x, 0), mode);
  6392.       if ((((HOST_WIDE_INT) 1 << (bitwidth - 1)) & sig) == 0)
  6393.         return (sig == 1 || sig == 0 ? bitwidth
  6394.             : bitwidth - floor_log2 (sig) - 1);
  6395.     }
  6396.  
  6397.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  6398.       num1 = num_sign_bit_copies (XEXP (x, 1), mode);
  6399.       return MAX (1, MIN (num0, num1) - 1);
  6400.       
  6401.     case MULT:
  6402.       /* The number of bits of the product is the sum of the number of
  6403.      bits of both terms.  However, unless one of the terms if known
  6404.      to be positive, we must allow for an additional bit since negating
  6405.      a negative number can remove one sign bit copy.  */
  6406.  
  6407.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  6408.       num1 = num_sign_bit_copies (XEXP (x, 1), mode);
  6409.  
  6410.       result = bitwidth - (bitwidth - num0) - (bitwidth - num1);
  6411.       if (result > 0
  6412.       && bitwidth <= HOST_BITS_PER_INT
  6413.       && ((significant_bits (XEXP (x, 0), mode)
  6414.            & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  6415.       && (significant_bits (XEXP (x, 1), mode)
  6416.           & ((HOST_WIDE_INT) 1 << (bitwidth - 1)) != 0))
  6417.     result--;
  6418.  
  6419.       return MAX (1, result);
  6420.  
  6421.     case UDIV:
  6422.       /* The result must be <= the first operand.  */
  6423.       return num_sign_bit_copies (XEXP (x, 0), mode);
  6424.  
  6425.     case UMOD:
  6426.       /* The result must be <= the scond operand.  */
  6427.       return num_sign_bit_copies (XEXP (x, 1), mode);
  6428.  
  6429.     case DIV:
  6430.       /* Similar to unsigned division, except that we have to worry about
  6431.      the case where the divisor is negative, in which case we have
  6432.      to add 1.  */
  6433.       result = num_sign_bit_copies (XEXP (x, 0), mode);
  6434.       if (result > 1
  6435.       && bitwidth <= HOST_BITS_PER_WIDE_INT
  6436.       && (significant_bits (XEXP (x, 1), mode)
  6437.           & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  6438.     result --;
  6439.  
  6440.       return result;
  6441.  
  6442.     case MOD:
  6443.       result = num_sign_bit_copies (XEXP (x, 1), mode);
  6444.       if (result > 1
  6445.       && bitwidth <= HOST_BITS_PER_WIDE_INT
  6446.       && (significant_bits (XEXP (x, 1), mode)
  6447.           & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  6448.     result --;
  6449.  
  6450.       return result;
  6451.  
  6452.     case ASHIFTRT:
  6453.       /* Shifts by a constant add to the number of bits equal to the
  6454.      sign bit.  */
  6455.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  6456.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  6457.       && INTVAL (XEXP (x, 1)) > 0)
  6458.     num0 = MIN (bitwidth, num0 + INTVAL (XEXP (x, 1)));
  6459.  
  6460.       return num0;
  6461.  
  6462.     case ASHIFT:
  6463.     case LSHIFT:
  6464.       /* Left shifts destroy copies.  */
  6465.       if (GET_CODE (XEXP (x, 1)) != CONST_INT
  6466.       || INTVAL (XEXP (x, 1)) < 0
  6467.       || INTVAL (XEXP (x, 1)) >= bitwidth)
  6468.     return 1;
  6469.  
  6470.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  6471.       return MAX (1, num0 - INTVAL (XEXP (x, 1)));
  6472.  
  6473.     case IF_THEN_ELSE:
  6474.       num0 = num_sign_bit_copies (XEXP (x, 1), mode);
  6475.       num1 = num_sign_bit_copies (XEXP (x, 2), mode);
  6476.       return MIN (num0, num1);
  6477.  
  6478. #if STORE_FLAG_VALUE == -1
  6479.     case EQ:  case NE:  case GE:  case GT:  case LE:  case LT:
  6480.     case GEU: case GTU: case LEU: case LTU:
  6481.       return bitwidth;
  6482. #endif
  6483.     }
  6484.  
  6485.   /* If we haven't been able to figure it out by one of the above rules,
  6486.      see if some of the high-order bits are known to be zero.  If so,
  6487.      count those bits and return one less than that amount.  If we can't
  6488.      safely compute the mask for this mode, always return BITWIDTH.  */
  6489.  
  6490.   if (bitwidth > HOST_BITS_PER_WIDE_INT)
  6491.     return 1;
  6492.  
  6493.   sig = significant_bits (x, mode);
  6494.   return sig == GET_MODE_MASK (mode) ? 1 : bitwidth - floor_log2 (sig) - 1;
  6495. }
  6496.  
  6497. /* Return the number of "extended" bits there are in X, when interpreted
  6498.    as a quantity in MODE whose signedness is indicated by UNSIGNEDP.  For
  6499.    unsigned quantities, this is the number of high-order zero bits.
  6500.    For signed quantities, this is the number of copies of the sign bit
  6501.    minus 1.  In both case, this function returns the number of "spare"
  6502.    bits.  For example, if two quantities for which this function returns
  6503.    at least 1 are added, the addition is known not to overflow.
  6504.  
  6505.    This function will always return 0 unless called during combine, which
  6506.    implies that it must be called from a define_split.  */
  6507.  
  6508. int
  6509. extended_count (x, mode, unsignedp)
  6510.      rtx x;
  6511.      enum machine_mode mode;
  6512.      int unsignedp;
  6513. {
  6514.   if (significant_valid == 0)
  6515.     return 0;
  6516.  
  6517.   return (unsignedp
  6518.       ? (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  6519.          && (GET_MODE_BITSIZE (mode) - 1
  6520.          - floor_log2 (significant_bits (x, mode))))
  6521.       : num_sign_bit_copies (x, mode) - 1);
  6522. }
  6523.  
  6524. /* This function is called from `simplify_shift_const' to merge two
  6525.    outer operations.  Specifically, we have already found that we need
  6526.    to perform operation *POP0 with constant *PCONST0 at the outermost
  6527.    position.  We would now like to also perform OP1 with constant CONST1
  6528.    (with *POP0 being done last).
  6529.  
  6530.    Return 1 if we can do the operation and update *POP0 and *PCONST0 with
  6531.    the resulting operation.  *PCOMP_P is set to 1 if we would need to 
  6532.    complement the innermost operand, otherwise it is unchanged.
  6533.  
  6534.    MODE is the mode in which the operation will be done.  No bits outside
  6535.    the width of this mode matter.  It is assumed that the width of this mode
  6536.    is smaller than or equal to HOST_BITS_PER_WIDE_INT.
  6537.  
  6538.    If *POP0 or OP1 are NIL, it means no operation is required.  Only NEG, PLUS,
  6539.    IOR, XOR, and AND are supported.  We may set *POP0 to SET if the proper
  6540.    result is simply *PCONST0.
  6541.  
  6542.    If the resulting operation cannot be expressed as one operation, we
  6543.    return 0 and do not change *POP0, *PCONST0, and *PCOMP_P.  */
  6544.  
  6545. static int
  6546. merge_outer_ops (pop0, pconst0, op1, const1, mode, pcomp_p)
  6547.      enum rtx_code *pop0;
  6548.      HOST_WIDE_INT *pconst0;
  6549.      enum rtx_code op1;
  6550.      HOST_WIDE_INT const1;
  6551.      enum machine_mode mode;
  6552.      int *pcomp_p;
  6553. {
  6554.   enum rtx_code op0 = *pop0;
  6555.   HOST_WIDE_INT const0 = *pconst0;
  6556.  
  6557.   const0 &= GET_MODE_MASK (mode);
  6558.   const1 &= GET_MODE_MASK (mode);
  6559.  
  6560.   /* If OP0 is an AND, clear unimportant bits in CONST1.  */
  6561.   if (op0 == AND)
  6562.     const1 &= const0;
  6563.  
  6564.   /* If OP0 or OP1 is NIL, this is easy.  Similarly if they are the same or
  6565.      if OP0 is SET.  */
  6566.  
  6567.   if (op1 == NIL || op0 == SET)
  6568.     return 1;
  6569.  
  6570.   else if (op0 == NIL)
  6571.     op0 = op1, const0 = const1;
  6572.  
  6573.   else if (op0 == op1)
  6574.     {
  6575.       switch (op0)
  6576.     {
  6577.     case AND:
  6578.       const0 &= const1;
  6579.       break;
  6580.     case IOR:
  6581.       const0 |= const1;
  6582.       break;
  6583.     case XOR:
  6584.       const0 ^= const1;
  6585.       break;
  6586.     case PLUS:
  6587.       const0 += const1;
  6588.       break;
  6589.     case NEG:
  6590.       op0 = NIL;
  6591.       break;
  6592.     }
  6593.     }
  6594.  
  6595.   /* Otherwise, if either is a PLUS or NEG, we can't do anything.  */
  6596.   else if (op0 == PLUS || op1 == PLUS || op0 == NEG || op1 == NEG)
  6597.     return 0;
  6598.  
  6599.   /* If the two constants aren't the same, we can't do anything.  The
  6600.      remaining six cases can all be done.  */
  6601.   else if (const0 != const1)
  6602.     return 0;
  6603.  
  6604.   else
  6605.     switch (op0)
  6606.       {
  6607.       case IOR:
  6608.     if (op1 == AND)
  6609.       /* (a & b) | b == b */
  6610.       op0 = SET;
  6611.     else /* op1 == XOR */
  6612.       /* (a ^ b) | b == a | b */
  6613.       ;
  6614.     break;
  6615.  
  6616.       case XOR:
  6617.     if (op1 == AND)
  6618.       /* (a & b) ^ b == (~a) & b */
  6619.       op0 = AND, *pcomp_p = 1;
  6620.     else /* op1 == IOR */
  6621.       /* (a | b) ^ b == a & ~b */
  6622.       op0 = AND, *pconst0 = ~ const0;
  6623.     break;
  6624.  
  6625.       case AND:
  6626.     if (op1 == IOR)
  6627.       /* (a | b) & b == b */
  6628.     op0 = SET;
  6629.     else /* op1 == XOR */
  6630.       /* (a ^ b) & b) == (~a) & b */
  6631.       *pcomp_p = 1;
  6632.     break;
  6633.       }
  6634.  
  6635.   /* Check for NO-OP cases.  */
  6636.   const0 &= GET_MODE_MASK (mode);
  6637.   if (const0 == 0
  6638.       && (op0 == IOR || op0 == XOR || op0 == PLUS))
  6639.     op0 = NIL;
  6640.   else if (const0 == 0 && op0 == AND)
  6641.     op0 = SET;
  6642.   else if (const0 == GET_MODE_MASK (mode) && op0 == AND)
  6643.     op0 = NIL;
  6644.  
  6645.   *pop0 = op0;
  6646.   *pconst0 = const0;
  6647.  
  6648.   return 1;
  6649. }
  6650.  
  6651. /* Simplify a shift of VAROP by COUNT bits.  CODE says what kind of shift.
  6652.    The result of the shift is RESULT_MODE.  X, if non-zero, is an expression
  6653.    that we started with.
  6654.  
  6655.    The shift is normally computed in the widest mode we find in VAROP, as
  6656.    long as it isn't a different number of words than RESULT_MODE.  Exceptions
  6657.    are ASHIFTRT and ROTATE, which are always done in their original mode,  */
  6658.  
  6659. static rtx
  6660. simplify_shift_const (x, code, result_mode, varop, count)
  6661.      rtx x;
  6662.      enum rtx_code code;
  6663.      enum machine_mode result_mode;
  6664.      rtx varop;
  6665.      int count;
  6666. {
  6667.   enum rtx_code orig_code = code;
  6668.   int orig_count = count;
  6669.   enum machine_mode mode = result_mode;
  6670.   enum machine_mode shift_mode, tmode;
  6671.   int mode_words
  6672.     = (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
  6673.   /* We form (outer_op (code varop count) (outer_const)).  */
  6674.   enum rtx_code outer_op = NIL;
  6675.   HOST_WIDE_INT outer_const;
  6676.   rtx const_rtx;
  6677.   int complement_p = 0;
  6678.   rtx new;
  6679.  
  6680.   /* If we were given an invalid count, don't do anything except exactly
  6681.      what was requested.  */
  6682.  
  6683.   if (count < 0 || count > GET_MODE_BITSIZE (mode))
  6684.     {
  6685.       if (x)
  6686.     return x;
  6687.  
  6688.       return gen_rtx (code, mode, varop, GEN_INT (count));
  6689.     }
  6690.  
  6691.   /* Unless one of the branches of the `if' in this loop does a `continue',
  6692.      we will `break' the loop after the `if'.  */
  6693.  
  6694.   while (count != 0)
  6695.     {
  6696.       /* If we have an operand of (clobber (const_int 0)), just return that
  6697.      value.  */
  6698.       if (GET_CODE (varop) == CLOBBER)
  6699.     return varop;
  6700.  
  6701.       /* If we discovered we had to complement VAROP, leave.  Making a NOT
  6702.      here would cause an infinite loop.  */
  6703.       if (complement_p)
  6704.     break;
  6705.  
  6706.       /* Convert ROTATETRT to ROTATE.  */
  6707.       if (code == ROTATERT)
  6708.     code = ROTATE, count = GET_MODE_BITSIZE (result_mode) - count;
  6709.  
  6710.       /* Canonicalize LSHIFT to ASHIFT.  */
  6711.       if (code == LSHIFT)
  6712.     code = ASHIFT;
  6713.  
  6714.       /* We need to determine what mode we will do the shift in.  If the
  6715.      shift is a ASHIFTRT or ROTATE, we must always do it in the mode it
  6716.      was originally done in.  Otherwise, we can do it in MODE, the widest
  6717.      mode encountered. */
  6718.       shift_mode = (code == ASHIFTRT || code == ROTATE ? result_mode : mode);
  6719.  
  6720.       /* Handle cases where the count is greater than the size of the mode
  6721.      minus 1.  For ASHIFT, use the size minus one as the count (this can
  6722.      occur when simplifying (lshiftrt (ashiftrt ..))).  For rotates,
  6723.      take the count modulo the size.  For other shifts, the result is
  6724.      zero.
  6725.  
  6726.      Since these shifts are being produced by the compiler by combining
  6727.      multiple operations, each of which are defined, we know what the
  6728.      result is supposed to be.  */
  6729.      
  6730.       if (count > GET_MODE_BITSIZE (shift_mode) - 1)
  6731.     {
  6732.       if (code == ASHIFTRT)
  6733.         count = GET_MODE_BITSIZE (shift_mode) - 1;
  6734.       else if (code == ROTATE || code == ROTATERT)
  6735.         count %= GET_MODE_BITSIZE (shift_mode);
  6736.       else
  6737.         {
  6738.           /* We can't simply return zero because there may be an
  6739.          outer op.  */
  6740.           varop = const0_rtx;
  6741.           count = 0;
  6742.           break;
  6743.         }
  6744.     }
  6745.  
  6746.       /* Negative counts are invalid and should not have been made (a
  6747.      programmer-specified negative count should have been handled
  6748.      above). */
  6749.       else if (count < 0)
  6750.     abort ();
  6751.  
  6752.       /* An arithmetic right shift of a quantity known to be -1 or 0
  6753.      is a no-op.  */
  6754.       if (code == ASHIFTRT
  6755.       && (num_sign_bit_copies (varop, shift_mode)
  6756.           == GET_MODE_BITSIZE (shift_mode)))
  6757.     {
  6758.       count = 0;
  6759.       break;
  6760.     }
  6761.  
  6762.       /* We simplify the tests below and elsewhere by converting
  6763.      ASHIFTRT to LSHIFTRT if we know the sign bit is clear.
  6764.      `make_compound_operation' will convert it to a ASHIFTRT for
  6765.      those machines (such as Vax) that don't have a LSHIFTRT.  */
  6766.       if (GET_MODE_BITSIZE (shift_mode) <= HOST_BITS_PER_WIDE_INT
  6767.       && code == ASHIFTRT
  6768.       && ((significant_bits (varop, shift_mode)
  6769.            & ((HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (shift_mode) - 1)))
  6770.           == 0))
  6771.     code = LSHIFTRT;
  6772.  
  6773.       switch (GET_CODE (varop))
  6774.     {
  6775.     case SIGN_EXTEND:
  6776.     case ZERO_EXTEND:
  6777.     case SIGN_EXTRACT:
  6778.     case ZERO_EXTRACT:
  6779.       new = expand_compound_operation (varop);
  6780.       if (new != varop)
  6781.         {
  6782.           varop = new;
  6783.           continue;
  6784.         }
  6785.       break;
  6786.  
  6787.     case MEM:
  6788.       /* If we have (xshiftrt (mem ...) C) and C is MODE_WIDTH
  6789.          minus the width of a smaller mode, we can do this with a
  6790.          SIGN_EXTEND or ZERO_EXTEND from the narrower memory location.  */
  6791.       if ((code == ASHIFTRT || code == LSHIFTRT)
  6792.           && ! mode_dependent_address_p (XEXP (varop, 0))
  6793.           && ! MEM_VOLATILE_P (varop)
  6794.           && (tmode = mode_for_size (GET_MODE_BITSIZE (mode) - count,
  6795.                      MODE_INT, 1)) != BLKmode)
  6796.         {
  6797. #if BYTES_BIG_ENDIAN
  6798.           new = gen_rtx (MEM, tmode, XEXP (varop, 0));
  6799. #else
  6800.           new = gen_rtx (MEM, tmode,
  6801.                  plus_constant (XEXP (varop, 0),
  6802.                         count / BITS_PER_UNIT));
  6803.           RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (varop);
  6804.           MEM_VOLATILE_P (new) = MEM_VOLATILE_P (varop);
  6805.           MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (varop);
  6806. #endif
  6807.           varop = gen_rtx_combine (code == ASHIFTRT ? SIGN_EXTEND
  6808.                        : ZERO_EXTEND, mode, new);
  6809.           count = 0;
  6810.           continue;
  6811.         }
  6812.       break;
  6813.  
  6814.     case USE:
  6815.       /* Similar to the case above, except that we can only do this if
  6816.          the resulting mode is the same as that of the underlying
  6817.          MEM and adjust the address depending on the *bits* endianness
  6818.          because of the way that bit-field extract insns are defined.  */
  6819.       if ((code == ASHIFTRT || code == LSHIFTRT)
  6820.           && (tmode = mode_for_size (GET_MODE_BITSIZE (mode) - count,
  6821.                      MODE_INT, 1)) != BLKmode
  6822.           && tmode == GET_MODE (XEXP (varop, 0)))
  6823.         {
  6824. #if BITS_BIG_ENDIAN
  6825.           new = XEXP (varop, 0);
  6826. #else
  6827.           new = copy_rtx (XEXP (varop, 0));
  6828.           SUBST (XEXP (new, 0), 
  6829.              plus_constant (XEXP (new, 0),
  6830.                     count / BITS_PER_UNIT));
  6831. #endif
  6832.  
  6833.           varop = gen_rtx_combine (code == ASHIFTRT ? SIGN_EXTEND
  6834.                        : ZERO_EXTEND, mode, new);
  6835.           count = 0;
  6836.           continue;
  6837.         }
  6838.       break;
  6839.  
  6840.     case SUBREG:
  6841.       /* If VAROP is a SUBREG, strip it as long as the inner operand has
  6842.          the same number of words as what we've seen so far.  Then store
  6843.          the widest mode in MODE.  */
  6844.       if (subreg_lowpart_p (varop)
  6845.           && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
  6846.           > GET_MODE_SIZE (GET_MODE (varop)))
  6847.           && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
  6848.             + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
  6849.           == mode_words))
  6850.         {
  6851.           varop = SUBREG_REG (varop);
  6852.           if (GET_MODE_SIZE (GET_MODE (varop)) > GET_MODE_SIZE (mode))
  6853.         mode = GET_MODE (varop);
  6854.           continue;
  6855.         }
  6856.       break;
  6857.  
  6858.     case MULT:
  6859.       /* Some machines use MULT instead of ASHIFT because MULT
  6860.          is cheaper.  But it is still better on those machines to
  6861.          merge two shifts into one.  */
  6862.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT
  6863.           && exact_log2 (INTVAL (XEXP (varop, 1))) >= 0)
  6864.         {
  6865.           varop = gen_binary (ASHIFT, GET_MODE (varop), XEXP (varop, 0),
  6866.                   GEN_INT (exact_log2 (INTVAL (XEXP (varop, 1)))));;
  6867.           continue;
  6868.         }
  6869.       break;
  6870.  
  6871.     case UDIV:
  6872.       /* Similar, for when divides are cheaper.  */
  6873.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT
  6874.           && exact_log2 (INTVAL (XEXP (varop, 1))) >= 0)
  6875.         {
  6876.           varop = gen_binary (LSHIFTRT, GET_MODE (varop), XEXP (varop, 0),
  6877.                   GEN_INT (exact_log2 (INTVAL (XEXP (varop, 1)))));
  6878.           continue;
  6879.         }
  6880.       break;
  6881.  
  6882.     case ASHIFTRT:
  6883.       /* If we are extracting just the sign bit of an arithmetic right 
  6884.          shift, that shift is not needed.  */
  6885.       if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1)
  6886.         {
  6887.           varop = XEXP (varop, 0);
  6888.           continue;
  6889.         }
  6890.  
  6891.       /* ... fall through ... */
  6892.  
  6893.     case LSHIFTRT:
  6894.     case ASHIFT:
  6895.     case LSHIFT:
  6896.     case ROTATE:
  6897.       /* Here we have two nested shifts.  The result is usually the
  6898.          AND of a new shift with a mask.  We compute the result below.  */
  6899.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT
  6900.           && INTVAL (XEXP (varop, 1)) >= 0
  6901.           && INTVAL (XEXP (varop, 1)) < GET_MODE_BITSIZE (GET_MODE (varop))
  6902.           && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT
  6903.           && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
  6904.         {
  6905.           enum rtx_code first_code = GET_CODE (varop);
  6906.           int first_count = INTVAL (XEXP (varop, 1));
  6907.           unsigned HOST_WIDE_INT mask;
  6908.           rtx mask_rtx;
  6909.           rtx inner;
  6910.  
  6911.           if (first_code == LSHIFT)
  6912.         first_code = ASHIFT;
  6913.  
  6914.           /* We have one common special case.  We can't do any merging if
  6915.          the inner code is an ASHIFTRT of a smaller mode.  However, if
  6916.          we have (ashift:M1 (subreg:M1 (ashiftrt:M2 FOO C1) 0) C2)
  6917.          with C2 == GET_MODE_BITSIZE (M1) - GET_MODE_BITSIZE (M2),
  6918.          we can convert it to
  6919.          (ashiftrt:M1 (ashift:M1 (and:M1 (subreg:M1 FOO 0 C2) C3) C1).
  6920.          This simplifies certain SIGN_EXTEND operations.  */
  6921.           if (code == ASHIFT && first_code == ASHIFTRT
  6922.           && (GET_MODE_BITSIZE (result_mode)
  6923.               - GET_MODE_BITSIZE (GET_MODE (varop))) == count)
  6924.         {
  6925.           /* C3 has the low-order C1 bits zero.  */
  6926.           
  6927.           mask = (GET_MODE_MASK (mode)
  6928.               & ~ (((HOST_WIDE_INT) 1 << first_count) - 1));
  6929.  
  6930.           varop = simplify_and_const_int (NULL_RTX, result_mode,
  6931.                           XEXP (varop, 0), mask);
  6932.           varop = simplify_shift_const (NULL_RTX, ASHIFT, result_mode,
  6933.                         varop, count);
  6934.           count = first_count;
  6935.           code = ASHIFTRT;
  6936.           continue;
  6937.         }
  6938.           
  6939.           /* If this was (ashiftrt (ashift foo C1) C2) and FOO has more
  6940.          than C1 high-order bits equal to the sign bit, we can convert
  6941.          this to either an ASHIFT or a ASHIFTRT depending on the
  6942.          two counts. 
  6943.  
  6944.          We cannot do this if VAROP's mode is not SHIFT_MODE.  */
  6945.  
  6946.           if (code == ASHIFTRT && first_code == ASHIFT
  6947.           && GET_MODE (varop) == shift_mode
  6948.           && (num_sign_bit_copies (XEXP (varop, 0), shift_mode)
  6949.               > first_count))
  6950.         {
  6951.           count -= first_count;
  6952.           if (count < 0)
  6953.             count = - count, code = ASHIFT;
  6954.           varop = XEXP (varop, 0);
  6955.           continue;
  6956.         }
  6957.  
  6958.           /* There are some cases we can't do.  If CODE is ASHIFTRT,
  6959.          we can only do this if FIRST_CODE is also ASHIFTRT.
  6960.  
  6961.          We can't do the case when CODE is ROTATE and FIRST_CODE is
  6962.          ASHIFTRT.
  6963.  
  6964.          If the mode of this shift is not the mode of the outer shift,
  6965.          we can't do this if either shift is ASHIFTRT or ROTATE.
  6966.  
  6967.          Finally, we can't do any of these if the mode is too wide
  6968.          unless the codes are the same.
  6969.  
  6970.          Handle the case where the shift codes are the same
  6971.          first.  */
  6972.  
  6973.           if (code == first_code)
  6974.         {
  6975.           if (GET_MODE (varop) != result_mode
  6976.               && (code == ASHIFTRT || code == ROTATE))
  6977.             break;
  6978.  
  6979.           count += first_count;
  6980.           varop = XEXP (varop, 0);
  6981.           continue;
  6982.         }
  6983.  
  6984.           if (code == ASHIFTRT
  6985.           || (code == ROTATE && first_code == ASHIFTRT)
  6986.           || GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
  6987.           || (GET_MODE (varop) != result_mode
  6988.               && (first_code == ASHIFTRT || first_code == ROTATE
  6989.               || code == ROTATE)))
  6990.         break;
  6991.  
  6992.           /* To compute the mask to apply after the shift, shift the
  6993.          significant bits of the inner shift the same way the 
  6994.          outer shift will.  */
  6995.  
  6996.           mask_rtx = GEN_INT (significant_bits (varop, GET_MODE (varop)));
  6997.  
  6998.           mask_rtx
  6999.         = simplify_binary_operation (code, result_mode, mask_rtx,
  7000.                          GEN_INT (count));
  7001.                   
  7002.           /* Give up if we can't compute an outer operation to use.  */
  7003.           if (mask_rtx == 0
  7004.           || GET_CODE (mask_rtx) != CONST_INT
  7005.           || ! merge_outer_ops (&outer_op, &outer_const, AND,
  7006.                     INTVAL (mask_rtx),
  7007.                     result_mode, &complement_p))
  7008.         break;
  7009.  
  7010.           /* If the shifts are in the same direction, we add the
  7011.          counts.  Otherwise, we subtract them.  */
  7012.           if ((code == ASHIFTRT || code == LSHIFTRT)
  7013.           == (first_code == ASHIFTRT || first_code == LSHIFTRT))
  7014.         count += first_count;
  7015.           else
  7016.         count -= first_count;
  7017.  
  7018.           /* If COUNT is positive, the new shift is usually CODE, 
  7019.          except for the two exceptions below, in which case it is
  7020.          FIRST_CODE.  If the count is negative, FIRST_CODE should
  7021.          always be used  */
  7022.           if (count > 0
  7023.           && ((first_code == ROTATE && code == ASHIFT)
  7024.               || (first_code == ASHIFTRT && code == LSHIFTRT)))
  7025.         code = first_code;
  7026.           else if (count < 0)
  7027.         code = first_code, count = - count;
  7028.  
  7029.           varop = XEXP (varop, 0);
  7030.           continue;
  7031.         }
  7032.  
  7033.       /* If we have (A << B << C) for any shift, we can convert this to
  7034.          (A << C << B).  This wins if A is a constant.  Only try this if
  7035.          B is not a constant.  */
  7036.  
  7037.       else if (GET_CODE (varop) == code
  7038.            && GET_CODE (XEXP (varop, 1)) != CONST_INT
  7039.            && 0 != (new
  7040.                 = simplify_binary_operation (code, mode,
  7041.                              XEXP (varop, 0),
  7042.                              GEN_INT (count))))
  7043.         {
  7044.           varop = gen_rtx_combine (code, mode, new, XEXP (varop, 1));
  7045.           count = 0;
  7046.           continue;
  7047.         }
  7048.       break;
  7049.  
  7050.     case NOT:
  7051.       /* Make this fit the case below.  */
  7052.       varop = gen_rtx_combine (XOR, mode, XEXP (varop, 0),
  7053.                    GEN_INT (GET_MODE_MASK (mode)));
  7054.       continue;
  7055.  
  7056.     case IOR:
  7057.     case AND:
  7058.     case XOR:
  7059.       /* If we have (xshiftrt (ior (plus X (const_int -1)) X) C)
  7060.          with C the size of VAROP - 1 and the shift is logical if
  7061.          STORE_FLAG_VALUE is 1 and arithmetic if STORE_FLAG_VALUE is -1,
  7062.          we have an (le X 0) operation.   If we have an arithmetic shift
  7063.          and STORE_FLAG_VALUE is 1 or we have a logical shift with
  7064.          STORE_FLAG_VALUE of -1, we have a (neg (le X 0)) operation.  */
  7065.  
  7066.       if (GET_CODE (varop) == IOR && GET_CODE (XEXP (varop, 0)) == PLUS
  7067.           && XEXP (XEXP (varop, 0), 1) == constm1_rtx
  7068.           && (STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
  7069.           && (code == LSHIFTRT || code == ASHIFTRT)
  7070.           && count == GET_MODE_BITSIZE (GET_MODE (varop)) - 1
  7071.           && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1)))
  7072.         {
  7073.           count = 0;
  7074.           varop = gen_rtx_combine (LE, GET_MODE (varop), XEXP (varop, 1),
  7075.                        const0_rtx);
  7076.  
  7077.           if (STORE_FLAG_VALUE == 1 ? code == ASHIFTRT : code == LSHIFTRT)
  7078.         varop = gen_rtx_combine (NEG, GET_MODE (varop), varop);
  7079.  
  7080.           continue;
  7081.         }
  7082.  
  7083.       /* If we have (shift (logical)), move the logical to the outside
  7084.          to allow it to possibly combine with another logical and the
  7085.          shift to combine with another shift.  This also canonicalizes to
  7086.          what a ZERO_EXTRACT looks like.  Also, some machines have
  7087.          (and (shift)) insns.  */
  7088.  
  7089.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT
  7090.           && (new = simplify_binary_operation (code, result_mode,
  7091.                            XEXP (varop, 1),
  7092.                            GEN_INT (count))) != 0
  7093.           && merge_outer_ops (&outer_op, &outer_const, GET_CODE (varop),
  7094.                   INTVAL (new), result_mode, &complement_p))
  7095.         {
  7096.           varop = XEXP (varop, 0);
  7097.           continue;
  7098.         }
  7099.  
  7100.       /* If we can't do that, try to simplify the shift in each arm of the
  7101.          logical expression, make a new logical expression, and apply
  7102.          the inverse distributive law.  */
  7103.       {
  7104.         rtx lhs = simplify_shift_const (NULL_RTX, code, result_mode,
  7105.                         XEXP (varop, 0), count);
  7106.         rtx rhs = simplify_shift_const (NULL_RTX, code, result_mode,
  7107.                         XEXP (varop, 1), count);
  7108.  
  7109.         varop = gen_binary (GET_CODE (varop), result_mode, lhs, rhs);
  7110.         varop = apply_distributive_law (varop);
  7111.  
  7112.         count = 0;
  7113.       }
  7114.       break;
  7115.  
  7116.     case EQ:
  7117.       /* convert (lshift (eq FOO 0) C) to (xor FOO 1) if STORE_FLAG_VALUE
  7118.          says that the sign bit can be tested, FOO has mode MODE, C is
  7119.          GET_MODE_BITSIZE (MODE) - 1, and FOO has only the low-order bit
  7120.          significant.  */
  7121.       if (code == LSHIFT
  7122.           && XEXP (varop, 1) == const0_rtx
  7123.           && GET_MODE (XEXP (varop, 0)) == result_mode
  7124.           && count == GET_MODE_BITSIZE (result_mode) - 1
  7125.           && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT
  7126.           && ((STORE_FLAG_VALUE
  7127.            & ((HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (result_mode) - 1))))
  7128.           && significant_bits (XEXP (varop, 0), result_mode) == 1
  7129.           && merge_outer_ops (&outer_op, &outer_const, XOR,
  7130.                   (HOST_WIDE_INT) 1, result_mode,
  7131.                   &complement_p))
  7132.         {
  7133.           varop = XEXP (varop, 0);
  7134.           count = 0;
  7135.           continue;
  7136.         }
  7137.       break;
  7138.  
  7139.     case NEG:
  7140.       /* (lshiftrt (neg A) C) where A is either 0 or 1 and C is one less
  7141.          than the number of bits in the mode is equivalent to A.  */
  7142.       if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1
  7143.           && significant_bits (XEXP (varop, 0), result_mode) == 1)
  7144.         {
  7145.           varop = XEXP (varop, 0);
  7146.           count = 0;
  7147.           continue;
  7148.         }
  7149.  
  7150.       /* NEG commutes with ASHIFT since it is multiplication.  Move the
  7151.          NEG outside to allow shifts to combine.  */
  7152.       if (code == ASHIFT
  7153.           && merge_outer_ops (&outer_op, &outer_const, NEG,
  7154.                   (HOST_WIDE_INT) 0, result_mode,
  7155.                   &complement_p))
  7156.         {
  7157.           varop = XEXP (varop, 0);
  7158.           continue;
  7159.         }
  7160.       break;
  7161.  
  7162.     case PLUS:
  7163.       /* (lshiftrt (plus A -1) C) where A is either 0 or 1 and C
  7164.          is one less than the number of bits in the mode is
  7165.          equivalent to (xor A 1).  */
  7166.       if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1
  7167.           && XEXP (varop, 1) == constm1_rtx
  7168.           && significant_bits (XEXP (varop, 0), result_mode) == 1
  7169.           && merge_outer_ops (&outer_op, &outer_const, XOR,
  7170.                   (HOST_WIDE_INT) 1, result_mode,
  7171.                   &complement_p))
  7172.         {
  7173.           count = 0;
  7174.           varop = XEXP (varop, 0);
  7175.           continue;
  7176.         }
  7177.  
  7178.       /* If we have (xshiftrt (plus FOO BAR) C), and the only bits
  7179.          significant in BAR are those being shifted out and those
  7180.          bits are known zero in FOO, we can replace the PLUS with FOO.
  7181.          Similarly in the other operand order.  This code occurs when
  7182.          we are computing the size of a variable-size array.  */
  7183.  
  7184.       if ((code == ASHIFTRT || code == LSHIFTRT)
  7185.           && count < HOST_BITS_PER_WIDE_INT
  7186.           && significant_bits (XEXP (varop, 1), result_mode) >> count == 0
  7187.           && (significant_bits (XEXP (varop, 1), result_mode)
  7188.           & significant_bits (XEXP (varop, 0), result_mode)) == 0)
  7189.         {
  7190.           varop = XEXP (varop, 0);
  7191.           continue;
  7192.         }
  7193.       else if ((code == ASHIFTRT || code == LSHIFTRT)
  7194.            && count < HOST_BITS_PER_WIDE_INT
  7195.            && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT
  7196.            && 0 == (significant_bits (XEXP (varop, 0), result_mode)
  7197.                 >> count)
  7198.            && 0 == (significant_bits (XEXP (varop, 0), result_mode)
  7199.                 & significant_bits (XEXP (varop, 1),
  7200.                          result_mode)))
  7201.         {
  7202.           varop = XEXP (varop, 1);
  7203.           continue;
  7204.         }
  7205.  
  7206.       /* (ashift (plus foo C) N) is (plus (ashift foo N) C').  */
  7207.       if (code == ASHIFT
  7208.           && GET_CODE (XEXP (varop, 1)) == CONST_INT
  7209.           && (new = simplify_binary_operation (ASHIFT, result_mode,
  7210.                            XEXP (varop, 1),
  7211.                            GEN_INT (count))) != 0
  7212.           && merge_outer_ops (&outer_op, &outer_const, PLUS,
  7213.                   INTVAL (new), result_mode, &complement_p))
  7214.         {
  7215.           varop = XEXP (varop, 0);
  7216.           continue;
  7217.         }
  7218.       break;
  7219.  
  7220.     case MINUS:
  7221.       /* If we have (xshiftrt (minus (ashiftrt X C)) X) C)
  7222.          with C the size of VAROP - 1 and the shift is logical if
  7223.          STORE_FLAG_VALUE is 1 and arithmetic if STORE_FLAG_VALUE is -1,
  7224.          we have a (gt X 0) operation.  If the shift is arithmetic with
  7225.          STORE_FLAG_VALUE of 1 or logical with STORE_FLAG_VALUE == -1,
  7226.          we have a (neg (gt X 0)) operation.  */
  7227.  
  7228.       if (GET_CODE (XEXP (varop, 0)) == ASHIFTRT
  7229.           && count == GET_MODE_BITSIZE (GET_MODE (varop)) - 1
  7230.           && (STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
  7231.           && (code == LSHIFTRT || code == ASHIFTRT)
  7232.           && GET_CODE (XEXP (XEXP (varop, 0), 1)) == CONST_INT
  7233.           && INTVAL (XEXP (XEXP (varop, 0), 1)) == count
  7234.           && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1)))
  7235.         {
  7236.           count = 0;
  7237.           varop = gen_rtx_combine (GT, GET_MODE (varop), XEXP (varop, 1),
  7238.                        const0_rtx);
  7239.  
  7240.           if (STORE_FLAG_VALUE == 1 ? code == ASHIFTRT : code == LSHIFTRT)
  7241.         varop = gen_rtx_combine (NEG, GET_MODE (varop), varop);
  7242.  
  7243.           continue;
  7244.         }
  7245.       break;
  7246.     }
  7247.  
  7248.       break;
  7249.     }
  7250.  
  7251.   /* We need to determine what mode to do the shift in.  If the shift is
  7252.      a ASHIFTRT or ROTATE, we must always do it in the mode it was originally
  7253.      done in.  Otherwise, we can do it in MODE, the widest mode encountered.
  7254.      The code we care about is that of the shift that will actually be done,
  7255.      not the shift that was originally requested.  */
  7256.   shift_mode = (code == ASHIFTRT || code == ROTATE ? result_mode : mode);
  7257.  
  7258.   /* We have now finished analyzing the shift.  The result should be
  7259.      a shift of type CODE with SHIFT_MODE shifting VAROP COUNT places.  If
  7260.      OUTER_OP is non-NIL, it is an operation that needs to be applied
  7261.      to the result of the shift.  OUTER_CONST is the relevant constant,
  7262.      but we must turn off all bits turned off in the shift.
  7263.  
  7264.      If we were passed a value for X, see if we can use any pieces of
  7265.      it.  If not, make new rtx.  */
  7266.  
  7267.   if (x && GET_RTX_CLASS (GET_CODE (x)) == '2'
  7268.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  7269.       && INTVAL (XEXP (x, 1)) == count)
  7270.     const_rtx = XEXP (x, 1);
  7271.   else
  7272.     const_rtx = GEN_INT (count);
  7273.  
  7274.   if (x && GET_CODE (XEXP (x, 0)) == SUBREG
  7275.       && GET_MODE (XEXP (x, 0)) == shift_mode
  7276.       && SUBREG_REG (XEXP (x, 0)) == varop)
  7277.     varop = XEXP (x, 0);
  7278.   else if (GET_MODE (varop) != shift_mode)
  7279.     varop = gen_lowpart_for_combine (shift_mode, varop);
  7280.  
  7281.   /* If we can't make the SUBREG, try to return what we were given. */
  7282.   if (GET_CODE (varop) == CLOBBER)
  7283.     return x ? x : varop;
  7284.  
  7285.   new = simplify_binary_operation (code, shift_mode, varop, const_rtx);
  7286.   if (new != 0)
  7287.     x = new;
  7288.   else
  7289.     {
  7290.       if (x == 0 || GET_CODE (x) != code || GET_MODE (x) != shift_mode)
  7291.     x = gen_rtx_combine (code, shift_mode, varop, const_rtx);
  7292.  
  7293.       SUBST (XEXP (x, 0), varop);
  7294.       SUBST (XEXP (x, 1), const_rtx);
  7295.     }
  7296.  
  7297.   /* If we were doing a LSHIFTRT in a wider mode than it was originally,
  7298.      turn off all the bits that the shift would have turned off.  */
  7299.   if (orig_code == LSHIFTRT && result_mode != shift_mode)
  7300.     x = simplify_and_const_int (NULL_RTX, shift_mode, x,
  7301.                 GET_MODE_MASK (result_mode) >> orig_count);
  7302.       
  7303.   /* Do the remainder of the processing in RESULT_MODE.  */
  7304.   x = gen_lowpart_for_combine (result_mode, x);
  7305.  
  7306.   /* If COMPLEMENT_P is set, we have to complement X before doing the outer
  7307.      operation.  */
  7308.   if (complement_p)
  7309.     x = gen_unary (NOT, result_mode, x);
  7310.  
  7311.   if (outer_op != NIL)
  7312.     {
  7313.       if (GET_MODE_BITSIZE (result_mode) < HOST_BITS_PER_WIDE_INT)
  7314.     outer_const &= GET_MODE_MASK (result_mode);
  7315.  
  7316.       if (outer_op == AND)
  7317.     x = simplify_and_const_int (NULL_RTX, result_mode, x, outer_const);
  7318.       else if (outer_op == SET)
  7319.     /* This means that we have determined that the result is
  7320.        equivalent to a constant.  This should be rare.  */
  7321.     x = GEN_INT (outer_const);
  7322.       else if (GET_RTX_CLASS (outer_op) == '1')
  7323.     x = gen_unary (outer_op, result_mode, x);
  7324.       else
  7325.     x = gen_binary (outer_op, result_mode, x, GEN_INT (outer_const));
  7326.     }
  7327.  
  7328.   return x;
  7329. }  
  7330.  
  7331. /* Like recog, but we receive the address of a pointer to a new pattern.
  7332.    We try to match the rtx that the pointer points to.
  7333.    If that fails, we may try to modify or replace the pattern,
  7334.    storing the replacement into the same pointer object.
  7335.  
  7336.    Modifications include deletion or addition of CLOBBERs.
  7337.  
  7338.    PNOTES is a pointer to a location where any REG_UNUSED notes added for
  7339.    the CLOBBERs are placed.
  7340.  
  7341.    The value is the final insn code from the pattern ultimately matched,
  7342.    or -1.  */
  7343.  
  7344. static int
  7345. recog_for_combine (pnewpat, insn, pnotes)
  7346.      rtx *pnewpat;
  7347.      rtx insn;
  7348.      rtx *pnotes;
  7349. {
  7350.   register rtx pat = *pnewpat;
  7351.   int insn_code_number;
  7352.   int num_clobbers_to_add = 0;
  7353.   int i;
  7354.   rtx notes = 0;
  7355.  
  7356.   /* Is the result of combination a valid instruction?  */
  7357.   insn_code_number = recog (pat, insn, &num_clobbers_to_add);
  7358.  
  7359.   /* If it isn't, there is the possibility that we previously had an insn
  7360.      that clobbered some register as a side effect, but the combined
  7361.      insn doesn't need to do that.  So try once more without the clobbers
  7362.      unless this represents an ASM insn.  */
  7363.  
  7364.   if (insn_code_number < 0 && ! check_asm_operands (pat)
  7365.       && GET_CODE (pat) == PARALLEL)
  7366.     {
  7367.       int pos;
  7368.  
  7369.       for (pos = 0, i = 0; i < XVECLEN (pat, 0); i++)
  7370.     if (GET_CODE (XVECEXP (pat, 0, i)) != CLOBBER)
  7371.       {
  7372.         if (i != pos)
  7373.           SUBST (XVECEXP (pat, 0, pos), XVECEXP (pat, 0, i));
  7374.         pos++;
  7375.       }
  7376.  
  7377.       SUBST_INT (XVECLEN (pat, 0), pos);
  7378.  
  7379.       if (pos == 1)
  7380.     pat = XVECEXP (pat, 0, 0);
  7381.  
  7382.       insn_code_number = recog (pat, insn, &num_clobbers_to_add);
  7383.     }
  7384.  
  7385.   /* If we had any clobbers to add, make a new pattern than contains
  7386.      them.  Then check to make sure that all of them are dead.  */
  7387.   if (num_clobbers_to_add)
  7388.     {
  7389.       rtx newpat = gen_rtx (PARALLEL, VOIDmode,
  7390.                 gen_rtvec (GET_CODE (pat) == PARALLEL
  7391.                        ? XVECLEN (pat, 0) + num_clobbers_to_add
  7392.                        : num_clobbers_to_add + 1));
  7393.  
  7394.       if (GET_CODE (pat) == PARALLEL)
  7395.     for (i = 0; i < XVECLEN (pat, 0); i++)
  7396.       XVECEXP (newpat, 0, i) = XVECEXP (pat, 0, i);
  7397.       else
  7398.     XVECEXP (newpat, 0, 0) = pat;
  7399.  
  7400.       add_clobbers (newpat, insn_code_number);
  7401.  
  7402.       for (i = XVECLEN (newpat, 0) - num_clobbers_to_add;
  7403.        i < XVECLEN (newpat, 0); i++)
  7404.     {
  7405.       if (GET_CODE (XEXP (XVECEXP (newpat, 0, i), 0)) == REG
  7406.           && ! reg_dead_at_p (XEXP (XVECEXP (newpat, 0, i), 0), insn))
  7407.         return -1;
  7408.       notes = gen_rtx (EXPR_LIST, REG_UNUSED,
  7409.                XEXP (XVECEXP (newpat, 0, i), 0), notes);
  7410.     }
  7411.       pat = newpat;
  7412.     }
  7413.  
  7414.   *pnewpat = pat;
  7415.   *pnotes = notes;
  7416.  
  7417.   return insn_code_number;
  7418. }
  7419.  
  7420. /* Like gen_lowpart but for use by combine.  In combine it is not possible
  7421.    to create any new pseudoregs.  However, it is safe to create
  7422.    invalid memory addresses, because combine will try to recognize
  7423.    them and all they will do is make the combine attempt fail.
  7424.  
  7425.    If for some reason this cannot do its job, an rtx
  7426.    (clobber (const_int 0)) is returned.
  7427.    An insn containing that will not be recognized.  */
  7428.  
  7429. #undef gen_lowpart
  7430.  
  7431. static rtx
  7432. gen_lowpart_for_combine (mode, x)
  7433.      enum machine_mode mode;
  7434.      register rtx x;
  7435. {
  7436.   rtx result;
  7437.  
  7438.   if (GET_MODE (x) == mode)
  7439.     return x;
  7440.  
  7441.   if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
  7442.     return gen_rtx (CLOBBER, GET_MODE (x), const0_rtx);
  7443.  
  7444.   /* X might be a paradoxical (subreg (mem)).  In that case, gen_lowpart
  7445.      won't know what to do.  So we will strip off the SUBREG here and
  7446.      process normally.  */
  7447.   if (GET_CODE (x) == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
  7448.     {
  7449.       x = SUBREG_REG (x);
  7450.       if (GET_MODE (x) == mode)
  7451.     return x;
  7452.     }
  7453.  
  7454.   result = gen_lowpart_common (mode, x);
  7455.   if (result)
  7456.     return result;
  7457.  
  7458.   if (GET_CODE (x) == MEM)
  7459.     {
  7460.       register int offset = 0;
  7461.       rtx new;
  7462.  
  7463.       /* Refuse to work on a volatile memory ref or one with a mode-dependent
  7464.      address.  */
  7465.       if (MEM_VOLATILE_P (x) || mode_dependent_address_p (XEXP (x, 0)))
  7466.     return gen_rtx (CLOBBER, GET_MODE (x), const0_rtx);
  7467.  
  7468.       /* If we want to refer to something bigger than the original memref,
  7469.      generate a perverse subreg instead.  That will force a reload
  7470.      of the original memref X.  */
  7471.       if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode))
  7472.     return gen_rtx (SUBREG, mode, x, 0);
  7473.  
  7474. #if WORDS_BIG_ENDIAN
  7475.       offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
  7476.         - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
  7477. #endif
  7478. #if BYTES_BIG_ENDIAN
  7479.       /* Adjust the address so that the address-after-the-data
  7480.      is unchanged.  */
  7481.       offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
  7482.          - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
  7483. #endif
  7484.       new = gen_rtx (MEM, mode, plus_constant (XEXP (x, 0), offset));
  7485.       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (x);
  7486.       MEM_VOLATILE_P (new) = MEM_VOLATILE_P (x);
  7487.       MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (x);
  7488.       return new;
  7489.     }
  7490.  
  7491.   /* If X is a comparison operator, rewrite it in a new mode.  This
  7492.      probably won't match, but may allow further simplifications.  */
  7493.   else if (GET_RTX_CLASS (GET_CODE (x)) == '<')
  7494.     return gen_rtx_combine (GET_CODE (x), mode, XEXP (x, 0), XEXP (x, 1));
  7495.  
  7496.   /* If we couldn't simplify X any other way, just enclose it in a
  7497.      SUBREG.  Normally, this SUBREG won't match, but some patterns may
  7498.      include an explicit SUBREG or we may simplify it further in combine.  */
  7499.   else
  7500.     {
  7501.       int word = 0;
  7502.  
  7503.       if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  7504.     word = ((GET_MODE_SIZE (GET_MODE (x))
  7505.          - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  7506.         / UNITS_PER_WORD);
  7507.       return gen_rtx (SUBREG, mode, x, word);
  7508.     }
  7509. }
  7510.  
  7511. /* Make an rtx expression.  This is a subset of gen_rtx and only supports
  7512.    expressions of 1, 2, or 3 operands, each of which are rtx expressions.
  7513.  
  7514.    If the identical expression was previously in the insn (in the undobuf),
  7515.    it will be returned.  Only if it is not found will a new expression
  7516.    be made.  */
  7517.  
  7518. /*VARARGS2*/
  7519. static rtx
  7520. gen_rtx_combine (va_alist)
  7521.      va_dcl
  7522. {
  7523.   va_list p;
  7524.   enum rtx_code code;
  7525.   enum machine_mode mode;
  7526.   int n_args;
  7527.   rtx args[3];
  7528.   int i, j;
  7529.   char *fmt;
  7530.   rtx rt;
  7531.  
  7532.   va_start (p);
  7533.   code = va_arg (p, enum rtx_code);
  7534.   mode = va_arg (p, enum machine_mode);
  7535.   n_args = GET_RTX_LENGTH (code);
  7536.   fmt = GET_RTX_FORMAT (code);
  7537.  
  7538.   if (n_args == 0 || n_args > 3)
  7539.     abort ();
  7540.  
  7541.   /* Get each arg and verify that it is supposed to be an expression.  */
  7542.   for (j = 0; j < n_args; j++)
  7543.     {
  7544.       if (*fmt++ != 'e')
  7545.     abort ();
  7546.  
  7547.       args[j] = va_arg (p, rtx);
  7548.     }
  7549.  
  7550.   /* See if this is in undobuf.  Be sure we don't use objects that came
  7551.      from another insn; this could produce circular rtl structures.  */
  7552.  
  7553.   for (i = previous_num_undos; i < undobuf.num_undo; i++)
  7554.     if (!undobuf.undo[i].is_int
  7555.     && GET_CODE (undobuf.undo[i].old_contents.rtx) == code
  7556.     && GET_MODE (undobuf.undo[i].old_contents.rtx) == mode)
  7557.       {
  7558.     for (j = 0; j < n_args; j++)
  7559.       if (XEXP (undobuf.undo[i].old_contents.rtx, j) != args[j])
  7560.         break;
  7561.  
  7562.     if (j == n_args)
  7563.       return undobuf.undo[i].old_contents.rtx;
  7564.       }
  7565.  
  7566.   /* Otherwise make a new rtx.  We know we have 1, 2, or 3 args.
  7567.      Use rtx_alloc instead of gen_rtx because it's faster on RISC.  */
  7568.   rt = rtx_alloc (code);
  7569.   PUT_MODE (rt, mode);
  7570.   XEXP (rt, 0) = args[0];
  7571.   if (n_args > 1)
  7572.     {
  7573.       XEXP (rt, 1) = args[1];
  7574.       if (n_args > 2)
  7575.     XEXP (rt, 2) = args[2];
  7576.     }
  7577.   return rt;
  7578. }
  7579.  
  7580. /* These routines make binary and unary operations by first seeing if they
  7581.    fold; if not, a new expression is allocated.  */
  7582.  
  7583. static rtx
  7584. gen_binary (code, mode, op0, op1)
  7585.      enum rtx_code code;
  7586.      enum machine_mode mode;
  7587.      rtx op0, op1;
  7588. {
  7589.   rtx result;
  7590.   rtx tem;
  7591.  
  7592.   if (GET_RTX_CLASS (code) == 'c'
  7593.       && (GET_CODE (op0) == CONST_INT
  7594.       || (CONSTANT_P (op0) && GET_CODE (op1) != CONST_INT)))
  7595.     tem = op0, op0 = op1, op1 = tem;
  7596.  
  7597.   if (GET_RTX_CLASS (code) == '<') 
  7598.     {
  7599.       enum machine_mode op_mode = GET_MODE (op0);
  7600.       if (op_mode == VOIDmode)
  7601.     op_mode = GET_MODE (op1);
  7602.       result = simplify_relational_operation (code, op_mode, op0, op1);
  7603.     }
  7604.   else
  7605.     result = simplify_binary_operation (code, mode, op0, op1);
  7606.  
  7607.   if (result)
  7608.     return result;
  7609.  
  7610.   /* Put complex operands first and constants second.  */
  7611.   if (GET_RTX_CLASS (code) == 'c'
  7612.       && ((CONSTANT_P (op0) && GET_CODE (op1) != CONST_INT)
  7613.       || (GET_RTX_CLASS (GET_CODE (op0)) == 'o'
  7614.           && GET_RTX_CLASS (GET_CODE (op1)) != 'o')
  7615.       || (GET_CODE (op0) == SUBREG
  7616.           && GET_RTX_CLASS (GET_CODE (SUBREG_REG (op0))) == 'o'
  7617.           && GET_RTX_CLASS (GET_CODE (op1)) != 'o')))
  7618.     return gen_rtx_combine (code, mode, op1, op0);
  7619.  
  7620.   return gen_rtx_combine (code, mode, op0, op1);
  7621. }
  7622.  
  7623. static rtx
  7624. gen_unary (code, mode, op0)
  7625.      enum rtx_code code;
  7626.      enum machine_mode mode;
  7627.      rtx op0;
  7628. {
  7629.   rtx result = simplify_unary_operation (code, mode, op0, mode);
  7630.  
  7631.   if (result)
  7632.     return result;
  7633.  
  7634.   return gen_rtx_combine (code, mode, op0);
  7635. }
  7636.  
  7637. #ifdef MPW
  7638. #pragma segment COMB03
  7639. #endif
  7640. /* Simplify a comparison between *POP0 and *POP1 where CODE is the
  7641.    comparison code that will be tested.
  7642.  
  7643.    The result is a possibly different comparison code to use.  *POP0 and
  7644.    *POP1 may be updated.
  7645.  
  7646.    It is possible that we might detect that a comparison is either always
  7647.    true or always false.  However, we do not perform general constant
  7648.    folding in combine, so this knowledge isn't useful.  Such tautologies
  7649.    should have been detected earlier.  Hence we ignore all such cases.  */
  7650.  
  7651. static enum rtx_code
  7652. simplify_comparison (code, pop0, pop1)
  7653.      enum rtx_code code;
  7654.      rtx *pop0;
  7655.      rtx *pop1;
  7656. {
  7657.   rtx op0 = *pop0;
  7658.   rtx op1 = *pop1;
  7659.   rtx tem, tem1;
  7660.   int i;
  7661.   enum machine_mode mode, tmode;
  7662.  
  7663.   /* Try a few ways of applying the same transformation to both operands.  */
  7664.   while (1)
  7665.     {
  7666.       /* If both operands are the same constant shift, see if we can ignore the
  7667.      shift.  We can if the shift is a rotate or if the bits shifted out of
  7668.      this shift are not significant for either input and if the type of
  7669.      comparison is compatible with the shift.  */
  7670.       if (GET_CODE (op0) == GET_CODE (op1)
  7671.       && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT
  7672.       && ((GET_CODE (op0) == ROTATE && (code == NE || code == EQ))
  7673.           || ((GET_CODE (op0) == LSHIFTRT
  7674.            || GET_CODE (op0) == ASHIFT || GET_CODE (op0) == LSHIFT)
  7675.           && (code != GT && code != LT && code != GE && code != LE))
  7676.           || (GET_CODE (op0) == ASHIFTRT
  7677.           && (code != GTU && code != LTU
  7678.               && code != GEU && code != GEU)))
  7679.       && GET_CODE (XEXP (op0, 1)) == CONST_INT
  7680.       && INTVAL (XEXP (op0, 1)) >= 0
  7681.       && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT
  7682.       && XEXP (op0, 1) == XEXP (op1, 1))
  7683.     {
  7684.       enum machine_mode mode = GET_MODE (op0);
  7685.       unsigned HOST_WIDE_INT mask = GET_MODE_MASK (mode);
  7686.       int shift_count = INTVAL (XEXP (op0, 1));
  7687.  
  7688.       if (GET_CODE (op0) == LSHIFTRT || GET_CODE (op0) == ASHIFTRT)
  7689.         mask &= (mask >> shift_count) << shift_count;
  7690.       else if (GET_CODE (op0) == ASHIFT || GET_CODE (op0) == LSHIFT)
  7691.         mask = (mask & (mask << shift_count)) >> shift_count;
  7692.  
  7693.       if ((significant_bits (XEXP (op0, 0), mode) & ~ mask) == 0
  7694.           && (significant_bits (XEXP (op1, 0), mode) & ~ mask) == 0)
  7695.         op0 = XEXP (op0, 0), op1 = XEXP (op1, 0);
  7696.       else
  7697.         break;
  7698.     }
  7699.  
  7700.       /* If both operands are AND's of a paradoxical SUBREG by constant, the
  7701.      SUBREGs are of the same mode, and, in both cases, the AND would
  7702.      be redundant if the comparison was done in the narrower mode,
  7703.      do the comparison in the narrower mode (e.g., we are AND'ing with 1
  7704.      and the operand's significant bits are 0xffffff01; in that case if
  7705.      we only care about QImode, we don't need the AND).  This case occurs
  7706.      if the output mode of an scc insn is not SImode and
  7707.      STORE_FLAG_VALUE == 1 (e.g., the 386).  */
  7708.  
  7709.       else if  (GET_CODE (op0) == AND && GET_CODE (op1) == AND
  7710.         && GET_CODE (XEXP (op0, 1)) == CONST_INT
  7711.         && GET_CODE (XEXP (op1, 1)) == CONST_INT
  7712.         && GET_CODE (XEXP (op0, 0)) == SUBREG
  7713.         && GET_CODE (XEXP (op1, 0)) == SUBREG
  7714.         && (GET_MODE_SIZE (GET_MODE (XEXP (op0, 0)))
  7715.             > GET_MODE_SIZE (GET_MODE (SUBREG_REG (XEXP (op0, 0)))))
  7716.         && (GET_MODE (SUBREG_REG (XEXP (op0, 0)))
  7717.             == GET_MODE (SUBREG_REG (XEXP (op1, 0))))
  7718.         && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (XEXP (op0, 0))))
  7719.             <= HOST_BITS_PER_WIDE_INT)
  7720.         && (significant_bits (SUBREG_REG (XEXP (op0, 0)),
  7721.                       GET_MODE (SUBREG_REG (XEXP (op0, 0))))
  7722.             & ~ INTVAL (XEXP (op0, 1))) == 0
  7723.         && (significant_bits (SUBREG_REG (XEXP (op1, 0)),
  7724.                       GET_MODE (SUBREG_REG (XEXP (op1, 0))))
  7725.             & ~ INTVAL (XEXP (op1, 1))) == 0)
  7726.     {
  7727.       op0 = SUBREG_REG (XEXP (op0, 0));
  7728.       op1 = SUBREG_REG (XEXP (op1, 0));
  7729.  
  7730.       /* the resulting comparison is always unsigned since we masked off
  7731.          the original sign bit. */
  7732.       code = unsigned_condition (code);
  7733.     }
  7734.       else
  7735.     break;
  7736.     }
  7737.      
  7738.   /* If the first operand is a constant, swap the operands and adjust the
  7739.      comparison code appropriately.  */
  7740.   if (CONSTANT_P (op0))
  7741.     {
  7742.       tem = op0, op0 = op1, op1 = tem;
  7743.       code = swap_condition (code);
  7744.     }
  7745.  
  7746.   /* We now enter a loop during which we will try to simplify the comparison.
  7747.      For the most part, we only are concerned with comparisons with zero,
  7748.      but some things may really be comparisons with zero but not start
  7749.      out looking that way.  */
  7750.  
  7751.   while (GET_CODE (op1) == CONST_INT)
  7752.     {
  7753.       enum machine_mode mode = GET_MODE (op0);
  7754.       int mode_width = GET_MODE_BITSIZE (mode);
  7755.       unsigned HOST_WIDE_INT mask = GET_MODE_MASK (mode);
  7756.       int equality_comparison_p;
  7757.       int sign_bit_comparison_p;
  7758.       int unsigned_comparison_p;
  7759.       HOST_WIDE_INT const_op;
  7760.  
  7761.       /* We only want to handle integral modes.  This catches VOIDmode,
  7762.      CCmode, and the floating-point modes.  An exception is that we
  7763.      can handle VOIDmode if OP0 is a COMPARE or a comparison
  7764.      operation.  */
  7765.  
  7766.       if (GET_MODE_CLASS (mode) != MODE_INT
  7767.       && ! (mode == VOIDmode
  7768.         && (GET_CODE (op0) == COMPARE
  7769.             || GET_RTX_CLASS (GET_CODE (op0)) == '<')))
  7770.     break;
  7771.  
  7772.       /* Get the constant we are comparing against and turn off all bits
  7773.      not on in our mode.  */
  7774.       const_op = INTVAL (op1);
  7775.       if (mode_width <= HOST_BITS_PER_WIDE_INT)
  7776.     const_op &= mask;
  7777.  
  7778.       /* If we are comparing against a constant power of two and the value
  7779.      being compared has only that single significant bit (e.g., it was
  7780.      `and'ed with that bit), we can replace this with a comparison
  7781.      with zero.  */
  7782.       if (const_op
  7783.       && (code == EQ || code == NE || code == GE || code == GEU
  7784.           || code == LT || code == LTU)
  7785.       && mode_width <= HOST_BITS_PER_WIDE_INT
  7786.       && exact_log2 (const_op) >= 0
  7787.       && significant_bits (op0, mode) == const_op)
  7788.     {
  7789.       code = (code == EQ || code == GE || code == GEU ? NE : EQ);
  7790.       op1 = const0_rtx, const_op = 0;
  7791.     }
  7792.  
  7793.       /* Similarly, if we are comparing a value known to be either -1 or
  7794.      0 with -1, change it to the opposite comparison against zero.  */
  7795.  
  7796.       if (const_op == -1
  7797.       && (code == EQ || code == NE || code == GT || code == LE
  7798.           || code == GEU || code == LTU)
  7799.       && num_sign_bit_copies (op0, mode) == mode_width)
  7800.     {
  7801.       code = (code == EQ || code == LE || code == GEU ? NE : EQ);
  7802.       op1 = const0_rtx, const_op = 0;
  7803.     }
  7804.  
  7805.       /* Do some canonicalizations based on the comparison code.  We prefer
  7806.      comparisons against zero and then prefer equality comparisons.  
  7807.      If we can reduce the size of a constant, we will do that too.  */
  7808.  
  7809.       switch (code)
  7810.     {
  7811.     case LT:
  7812.       /* < C is equivalent to <= (C - 1) */
  7813.       if (const_op > 0)
  7814.         {
  7815.           const_op -= 1;
  7816.           op1 = GEN_INT (const_op);
  7817.           code = LE;
  7818.           /* ... fall through to LE case below.  */
  7819.         }
  7820.       else
  7821.         break;
  7822.  
  7823.     case LE:
  7824.       /* <= C is equivalent to < (C + 1); we do this for C < 0  */
  7825.       if (const_op < 0)
  7826.         {
  7827.           const_op += 1;
  7828.           op1 = GEN_INT (const_op);
  7829.           code = LT;
  7830.         }
  7831.  
  7832.       /* If we are doing a <= 0 comparison on a value known to have
  7833.          a zero sign bit, we can replace this with == 0.  */
  7834.       else if (const_op == 0
  7835.            && mode_width <= HOST_BITS_PER_WIDE_INT
  7836.            && (significant_bits (op0, mode)
  7837.                & ((HOST_WIDE_INT) 1 << (mode_width - 1))) == 0)
  7838.         code = EQ;
  7839.       break;
  7840.  
  7841.     case GE:
  7842.       /* >= C is equivalent to > (C - 1). */
  7843.       if (const_op > 0)
  7844.         {
  7845.           const_op -= 1;
  7846.           op1 = GEN_INT (const_op);
  7847.           code = GT;
  7848.           /* ... fall through to GT below.  */
  7849.         }
  7850.       else
  7851.         break;
  7852.  
  7853.     case GT:
  7854.       /* > C is equivalent to >= (C + 1); we do this for C < 0*/
  7855.       if (const_op < 0)
  7856.         {
  7857.           const_op += 1;
  7858.           op1 = GEN_INT (const_op);
  7859.           code = GE;
  7860.         }
  7861.  
  7862.       /* If we are doing a > 0 comparison on a value known to have
  7863.          a zero sign bit, we can replace this with != 0.  */
  7864.       else if (const_op == 0
  7865.            && mode_width <= HOST_BITS_PER_WIDE_INT
  7866.            && (significant_bits (op0, mode)
  7867.                & ((HOST_WIDE_INT) 1 << (mode_width - 1))) == 0)
  7868.         code = NE;
  7869.       break;
  7870.  
  7871.     case LTU:
  7872.       /* < C is equivalent to <= (C - 1).  */
  7873.       if (const_op > 0)
  7874.         {
  7875.           const_op -= 1;
  7876.           op1 = GEN_INT (const_op);
  7877.           code = LEU;
  7878.           /* ... fall through ... */
  7879.         }
  7880.  
  7881.       /* (unsigned) < 0x80000000 is equivalent to >= 0.  */
  7882.       else if (const_op == (HOST_WIDE_INT) 1 << (mode_width - 1))
  7883.         {
  7884.           const_op = 0, op1 = const0_rtx;
  7885.           code = GE;
  7886.           break;
  7887.         }
  7888.       else
  7889.         break;
  7890.  
  7891.     case LEU:
  7892.       /* unsigned <= 0 is equivalent to == 0 */
  7893.       if (const_op == 0)
  7894.         code = EQ;
  7895.  
  7896.       /* (unsigned) <= 0x7fffffff is equivalent to >= 0. */
  7897.       else if (const_op == ((HOST_WIDE_INT) 1 << (mode_width - 1)) - 1)
  7898.         {
  7899.           const_op = 0, op1 = const0_rtx;
  7900.           code = GE;
  7901.         }
  7902.       break;
  7903.  
  7904.     case GEU:
  7905.       /* >= C is equivalent to < (C - 1).  */
  7906.       if (const_op > 1)
  7907.         {
  7908.           const_op -= 1;
  7909.           op1 = GEN_INT (const_op);
  7910.           code = GTU;
  7911.           /* ... fall through ... */
  7912.         }
  7913.  
  7914.       /* (unsigned) >= 0x80000000 is equivalent to < 0.  */
  7915.       else if (const_op == (HOST_WIDE_INT) 1 << (mode_width - 1))
  7916.         {
  7917.           const_op = 0, op1 = const0_rtx;
  7918.           code = LT;
  7919.         }
  7920.       else
  7921.         break;
  7922.  
  7923.     case GTU:
  7924.       /* unsigned > 0 is equivalent to != 0 */
  7925.       if (const_op == 0)
  7926.         code = NE;
  7927.  
  7928.       /* (unsigned) > 0x7fffffff is equivalent to < 0.  */
  7929.       else if (const_op == ((HOST_WIDE_INT) 1 << (mode_width - 1)) - 1)
  7930.         {
  7931.           const_op = 0, op1 = const0_rtx;
  7932.           code = LT;
  7933.         }
  7934.       break;
  7935.     }
  7936.  
  7937.       /* Compute some predicates to simplify code below.  */
  7938.  
  7939.       equality_comparison_p = (code == EQ || code == NE);
  7940.       sign_bit_comparison_p = ((code == LT || code == GE) && const_op == 0);
  7941.       unsigned_comparison_p = (code == LTU || code == LEU || code == GTU
  7942.                    || code == LEU);
  7943.  
  7944.       /* Now try cases based on the opcode of OP0.  If none of the cases
  7945.      does a "continue", we exit this loop immediately after the
  7946.      switch.  */
  7947.  
  7948.       switch (GET_CODE (op0))
  7949.     {
  7950.     case ZERO_EXTRACT:
  7951.       /* If we are extracting a single bit from a variable position in
  7952.          a constant that has only a single bit set and are comparing it
  7953.          with zero, we can convert this into an equality comparison 
  7954.          between the position and the location of the single bit.  We can't
  7955.          do this if bit endian and we don't have an extzv since we then
  7956.          can't know what mode to use for the endianness adjustment.  */
  7957.  
  7958. #if ! BITS_BIG_ENDIAN || defined (HAVE_extzv)
  7959.       if (GET_CODE (XEXP (op0, 0)) == CONST_INT
  7960.           && XEXP (op0, 1) == const1_rtx
  7961.           && equality_comparison_p && const_op == 0
  7962.           && (i = exact_log2 (INTVAL (XEXP (op0, 0)))) >= 0)
  7963.         {
  7964. #if BITS_BIG_ENDIAN
  7965.           i = (GET_MODE_BITSIZE
  7966.            (insn_operand_mode[(int) CODE_FOR_extzv][1]) - 1 - i);
  7967. #endif
  7968.  
  7969.           op0 = XEXP (op0, 2);
  7970.           op1 = GEN_INT (i);
  7971.           const_op = i;
  7972.  
  7973.           /* Result is nonzero iff shift count is equal to I.  */
  7974.           code = reverse_condition (code);
  7975.           continue;
  7976.         }
  7977. #endif
  7978.  
  7979.       /* ... fall through ... */
  7980.  
  7981.     case SIGN_EXTRACT:
  7982.       tem = expand_compound_operation (op0);
  7983.       if (tem != op0)
  7984.         {
  7985.           op0 = tem;
  7986.           continue;
  7987.         }
  7988.       break;
  7989.  
  7990.     case NOT:
  7991.       /* If testing for equality, we can take the NOT of the constant.  */
  7992.       if (equality_comparison_p
  7993.           && (tem = simplify_unary_operation (NOT, mode, op1, mode)) != 0)
  7994.         {
  7995.           op0 = XEXP (op0, 0);
  7996.           op1 = tem;
  7997.           continue;
  7998.         }
  7999.  
  8000.       /* If just looking at the sign bit, reverse the sense of the
  8001.          comparison.  */
  8002.       if (sign_bit_comparison_p)
  8003.         {
  8004.           op0 = XEXP (op0, 0);
  8005.           code = (code == GE ? LT : GE);
  8006.           continue;
  8007.         }
  8008.       break;
  8009.  
  8010.     case NEG:
  8011.       /* If testing for equality, we can take the NEG of the constant.  */
  8012.       if (equality_comparison_p
  8013.           && (tem = simplify_unary_operation (NEG, mode, op1, mode)) != 0)
  8014.         {
  8015.           op0 = XEXP (op0, 0);
  8016.           op1 = tem;
  8017.           continue;
  8018.         }
  8019.  
  8020.       /* The remaining cases only apply to comparisons with zero.  */
  8021.       if (const_op != 0)
  8022.         break;
  8023.  
  8024.       /* When X is ABS or is known positive,
  8025.          (neg X) is < 0 if and only if X != 0.  */
  8026.  
  8027.       if (sign_bit_comparison_p
  8028.           && (GET_CODE (XEXP (op0, 0)) == ABS
  8029.           || (mode_width <= HOST_BITS_PER_WIDE_INT
  8030.               && (significant_bits (XEXP (op0, 0), mode)
  8031.               & ((HOST_WIDE_INT) 1 << (mode_width - 1))) == 0)))
  8032.         {
  8033.           op0 = XEXP (op0, 0);
  8034.           code = (code == LT ? NE : EQ);
  8035.           continue;
  8036.         }
  8037.  
  8038.       /* If we have NEG of something that is the result of a
  8039.          SIGN_EXTEND, SIGN_EXTRACT, or ASHIFTRT, we know that the
  8040.          two high-order bits must be the same and hence that
  8041.          "(-a) < 0" is equivalent to "a > 0".  Otherwise, we can't
  8042.          do this.  */
  8043.       if (GET_CODE (XEXP (op0, 0)) == SIGN_EXTEND
  8044.           || (GET_CODE (XEXP (op0, 0)) == SIGN_EXTRACT
  8045.           && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
  8046.           && (INTVAL (XEXP (XEXP (op0, 0), 1))
  8047.               < GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (op0, 0), 0)))))
  8048.           || (GET_CODE (XEXP (op0, 0)) == ASHIFTRT
  8049.           && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
  8050.           && XEXP (XEXP (op0, 0), 1) != const0_rtx)
  8051.           || ((tem = get_last_value (XEXP (op0, 0))) != 0
  8052.           && (GET_CODE (tem) == SIGN_EXTEND
  8053.               || (GET_CODE (tem) == SIGN_EXTRACT
  8054.               && GET_CODE (XEXP (tem, 1)) == CONST_INT
  8055.               && (INTVAL (XEXP (tem, 1))
  8056.                   < GET_MODE_BITSIZE (GET_MODE (XEXP (tem, 0)))))
  8057.               || (GET_CODE (tem) == ASHIFTRT
  8058.               && GET_CODE (XEXP (tem, 1)) == CONST_INT
  8059.               && XEXP (tem, 1) != const0_rtx))))
  8060.         {
  8061.           op0 = XEXP (op0, 0);
  8062.           code = swap_condition (code);
  8063.           continue;
  8064.         }
  8065.       break;
  8066.  
  8067.     case ROTATE:
  8068.       /* If we are testing equality and our count is a constant, we
  8069.          can perform the inverse operation on our RHS.  */
  8070.       if (equality_comparison_p && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8071.           && (tem = simplify_binary_operation (ROTATERT, mode,
  8072.                            op1, XEXP (op0, 1))) != 0)
  8073.         {
  8074.           op0 = XEXP (op0, 0);
  8075.           op1 = tem;
  8076.           continue;
  8077.         }
  8078.  
  8079.       /* If we are doing a < 0 or >= 0 comparison, it means we are testing
  8080.          a particular bit.  Convert it to an AND of a constant of that
  8081.          bit.  This will be converted into a ZERO_EXTRACT.  */
  8082.       if (const_op == 0 && sign_bit_comparison_p
  8083.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8084.           && mode_width <= HOST_BITS_PER_WIDE_INT)
  8085.         {
  8086.           op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
  8087.                         ((HOST_WIDE_INT) 1
  8088.                          << (mode_width - 1
  8089.                          - INTVAL (XEXP (op0, 1)))));
  8090.           code = (code == LT ? NE : EQ);
  8091.           continue;
  8092.         }
  8093.  
  8094.       /* ... fall through ... */
  8095.  
  8096.     case ABS:
  8097.       /* ABS is ignorable inside an equality comparison with zero.  */
  8098.       if (const_op == 0 && equality_comparison_p)
  8099.         {
  8100.           op0 = XEXP (op0, 0);
  8101.           continue;
  8102.         }
  8103.       break;
  8104.       
  8105.  
  8106.     case SIGN_EXTEND:
  8107.       /* Can simplify (compare (zero/sign_extend FOO) CONST)
  8108.          to (compare FOO CONST) if CONST fits in FOO's mode and we 
  8109.          are either testing inequality or have an unsigned comparison
  8110.          with ZERO_EXTEND or a signed comparison with SIGN_EXTEND.  */
  8111.       if (! unsigned_comparison_p
  8112.           && (GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
  8113.           <= HOST_BITS_PER_WIDE_INT)
  8114.           && ((unsigned HOST_WIDE_INT) const_op
  8115.           < (((HOST_WIDE_INT) 1
  8116.               << (GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))) - 1)))))
  8117.         {
  8118.           op0 = XEXP (op0, 0);
  8119.           continue;
  8120.         }
  8121.       break;
  8122.  
  8123.     case SUBREG:
  8124.       /* Check for the case where we are comparing A - C1 with C2,
  8125.          both constants are smaller than 1/2 the maxium positive
  8126.          value in MODE, and the comparison is equality or unsigned.
  8127.          In that case, if A is either zero-extended to MODE or has
  8128.          sufficient sign bits so that the high-order bit in MODE
  8129.          is a copy of the sign in the inner mode, we can prove that it is
  8130.          safe to do the operation in the wider mode.  This simplifies
  8131.          many range checks.  */
  8132.  
  8133.       if (mode_width <= HOST_BITS_PER_WIDE_INT
  8134.           && subreg_lowpart_p (op0)
  8135.           && GET_CODE (SUBREG_REG (op0)) == PLUS
  8136.           && GET_CODE (XEXP (SUBREG_REG (op0), 1)) == CONST_INT
  8137.           && INTVAL (XEXP (SUBREG_REG (op0), 1)) < 0
  8138.           && (- INTVAL (XEXP (SUBREG_REG (op0), 1))
  8139.           < GET_MODE_MASK (mode) / 2)
  8140.           && (unsigned) const_op < GET_MODE_MASK (mode) / 2
  8141.           && (0 == (significant_bits (XEXP (SUBREG_REG (op0), 0),
  8142.                       GET_MODE (SUBREG_REG (op0)))
  8143.             & ~ GET_MODE_MASK (mode))
  8144.           || (num_sign_bit_copies (XEXP (SUBREG_REG (op0), 0),
  8145.                        GET_MODE (SUBREG_REG (op0)))
  8146.               > (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
  8147.              - GET_MODE_BITSIZE (mode)))))
  8148.         {
  8149.           op0 = SUBREG_REG (op0);
  8150.           continue;
  8151.         }
  8152.  
  8153.       /* If the inner mode is narrower and we are extracting the low part,
  8154.          we can treat the SUBREG as if it were a ZERO_EXTEND.  */
  8155.       if (subreg_lowpart_p (op0)
  8156.           && GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0))) < mode_width)
  8157.         /* Fall through */ ;
  8158.       else
  8159.         break;
  8160.  
  8161.       /* ... fall through ... */
  8162.  
  8163.     case ZERO_EXTEND:
  8164.       if ((unsigned_comparison_p || equality_comparison_p)
  8165.           && (GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
  8166.           <= HOST_BITS_PER_WIDE_INT)
  8167.           && ((unsigned HOST_WIDE_INT) const_op
  8168.           < GET_MODE_MASK (GET_MODE (XEXP (op0, 0)))))
  8169.         {
  8170.           op0 = XEXP (op0, 0);
  8171.           continue;
  8172.         }
  8173.       break;
  8174.  
  8175.     case PLUS:
  8176.       /* (eq (plus X C1) C2) -> (eq X (minus C2 C1)).  We can only do
  8177.          this for equality comparisons due to pathological cases involving
  8178.          overflows.  */
  8179.       if (equality_comparison_p && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8180.           && (tem = simplify_binary_operation (MINUS, mode, op1,
  8181.                            XEXP (op0, 1))) != 0)
  8182.         {
  8183.           op0 = XEXP (op0, 0);
  8184.           op1 = tem;
  8185.           continue;
  8186.         }
  8187.  
  8188.       /* (plus (abs X) (const_int -1)) is < 0 if and only if X == 0.  */
  8189.       if (const_op == 0 && XEXP (op0, 1) == constm1_rtx
  8190.           && GET_CODE (XEXP (op0, 0)) == ABS && sign_bit_comparison_p)
  8191.         {
  8192.           op0 = XEXP (XEXP (op0, 0), 0);
  8193.           code = (code == LT ? EQ : NE);
  8194.           continue;
  8195.         }
  8196.       break;
  8197.  
  8198.     case MINUS:
  8199.       /* The sign bit of (minus (ashiftrt X C) X), where C is the number
  8200.          of bits in X minus 1, is one iff X > 0.  */
  8201.       if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 0)) == ASHIFTRT
  8202.           && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
  8203.           && INTVAL (XEXP (XEXP (op0, 0), 1)) == mode_width - 1
  8204.           && rtx_equal_p (XEXP (XEXP (op0, 0), 0), XEXP (op0, 1)))
  8205.         {
  8206.           op0 = XEXP (op0, 1);
  8207.           code = (code == GE ? LE : GT);
  8208.           continue;
  8209.         }
  8210.       break;
  8211.  
  8212.     case XOR:
  8213.       /* (eq (xor A B) C) -> (eq A (xor B C)).  This is a simplification
  8214.          if C is zero or B is a constant.  */
  8215.       if (equality_comparison_p
  8216.           && 0 != (tem = simplify_binary_operation (XOR, mode,
  8217.                             XEXP (op0, 1), op1)))
  8218.         {
  8219.           op0 = XEXP (op0, 0);
  8220.           op1 = tem;
  8221.           continue;
  8222.         }
  8223.       break;
  8224.  
  8225.     case EQ:  case NE:
  8226.     case LT:  case LTU:  case LE:  case LEU:
  8227.     case GT:  case GTU:  case GE:  case GEU:
  8228.       /* We can't do anything if OP0 is a condition code value, rather
  8229.          than an actual data value.  */
  8230.       if (const_op != 0
  8231. #ifdef HAVE_cc0
  8232.           || XEXP (op0, 0) == cc0_rtx
  8233. #endif
  8234.           || GET_MODE_CLASS (GET_MODE (XEXP (op0, 0))) == MODE_CC)
  8235.         break;
  8236.  
  8237.       /* Get the two operands being compared.  */
  8238.       if (GET_CODE (XEXP (op0, 0)) == COMPARE)
  8239.         tem = XEXP (XEXP (op0, 0), 0), tem1 = XEXP (XEXP (op0, 0), 1);
  8240.       else
  8241.         tem = XEXP (op0, 0), tem1 = XEXP (op0, 1);
  8242.  
  8243.       /* Check for the cases where we simply want the result of the
  8244.          earlier test or the opposite of that result.  */
  8245.       if (code == NE
  8246.           || (code == EQ && reversible_comparison_p (op0))
  8247.           || (GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT
  8248.           && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
  8249.           && (STORE_FLAG_VALUE
  8250.               & (((HOST_WIDE_INT) 1
  8251.               << (GET_MODE_BITSIZE (GET_MODE (op0)) - 1))))
  8252.           && (code == LT
  8253.               || (code == GE && reversible_comparison_p (op0)))))
  8254.         {
  8255.           code = (code == LT || code == NE
  8256.               ? GET_CODE (op0) : reverse_condition (GET_CODE (op0)));
  8257.           op0 = tem, op1 = tem1;
  8258.           continue;
  8259.         }
  8260.       break;
  8261.  
  8262.     case IOR:
  8263.       /* The sign bit of (ior (plus X (const_int -1)) X) is non-zero
  8264.          iff X <= 0.  */
  8265.       if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 0)) == PLUS
  8266.           && XEXP (XEXP (op0, 0), 1) == constm1_rtx
  8267.           && rtx_equal_p (XEXP (XEXP (op0, 0), 0), XEXP (op0, 1)))
  8268.         {
  8269.           op0 = XEXP (op0, 1);
  8270.           code = (code == GE ? GT : LE);
  8271.           continue;
  8272.         }
  8273.       break;
  8274.  
  8275.     case AND:
  8276.       /* Convert (and (xshift 1 X) Y) to (and (lshiftrt Y X) 1).  This
  8277.          will be converted to a ZERO_EXTRACT later.  */
  8278.       if (const_op == 0 && equality_comparison_p
  8279.           && (GET_CODE (XEXP (op0, 0)) == ASHIFT
  8280.           || GET_CODE (XEXP (op0, 0)) == LSHIFT)
  8281.           && XEXP (XEXP (op0, 0), 0) == const1_rtx)
  8282.         {
  8283.           op0 = simplify_and_const_int
  8284.         (op0, mode, gen_rtx_combine (LSHIFTRT, mode,
  8285.                          XEXP (op0, 1),
  8286.                          XEXP (XEXP (op0, 0), 1)),
  8287.          (HOST_WIDE_INT) 1);
  8288.           continue;
  8289.         }
  8290.  
  8291.       /* If we are comparing (and (lshiftrt X C1) C2) for equality with
  8292.          zero and X is a comparison and C1 and C2 describe only bits set
  8293.          in STORE_FLAG_VALUE, we can compare with X.  */
  8294.       if (const_op == 0 && equality_comparison_p
  8295.           && mode_width <= HOST_BITS_PER_WIDE_INT
  8296.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8297.           && GET_CODE (XEXP (op0, 0)) == LSHIFTRT
  8298.           && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
  8299.           && INTVAL (XEXP (XEXP (op0, 0), 1)) >= 0
  8300.           && INTVAL (XEXP (XEXP (op0, 0), 1)) < HOST_BITS_PER_WIDE_INT)
  8301.         {
  8302.           mask = ((INTVAL (XEXP (op0, 1)) & GET_MODE_MASK (mode))
  8303.               << INTVAL (XEXP (XEXP (op0, 0), 1)));
  8304.           if ((~ STORE_FLAG_VALUE & mask) == 0
  8305.           && (GET_RTX_CLASS (GET_CODE (XEXP (XEXP (op0, 0), 0))) == '<'
  8306.               || ((tem = get_last_value (XEXP (XEXP (op0, 0), 0))) != 0
  8307.               && GET_RTX_CLASS (GET_CODE (tem)) == '<')))
  8308.         {
  8309.           op0 = XEXP (XEXP (op0, 0), 0);
  8310.           continue;
  8311.         }
  8312.         }
  8313.  
  8314.       /* If we are doing an equality comparison of an AND of a bit equal
  8315.          to the sign bit, replace this with a LT or GE comparison of
  8316.          the underlying value.  */
  8317.       if (equality_comparison_p
  8318.           && const_op == 0
  8319.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8320.           && mode_width <= HOST_BITS_PER_WIDE_INT
  8321.           && ((INTVAL (XEXP (op0, 1)) & GET_MODE_MASK (mode))
  8322.           == (HOST_WIDE_INT) 1 << (mode_width - 1)))
  8323.         {
  8324.           op0 = XEXP (op0, 0);
  8325.           code = (code == EQ ? GE : LT);
  8326.           continue;
  8327.         }
  8328.  
  8329.       /* If this AND operation is really a ZERO_EXTEND from a narrower
  8330.          mode, the constant fits within that mode, and this is either an
  8331.          equality or unsigned comparison, try to do this comparison in
  8332.          the narrower mode.  */
  8333.       if ((equality_comparison_p || unsigned_comparison_p)
  8334.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8335.           && (i = exact_log2 ((INTVAL (XEXP (op0, 1))
  8336.                    & GET_MODE_MASK (mode))
  8337.                   + 1)) >= 0
  8338.           && const_op >> i == 0
  8339.           && (tmode = mode_for_size (i, MODE_INT, 1)) != BLKmode)
  8340.         {
  8341.           op0 = gen_lowpart_for_combine (tmode, XEXP (op0, 0));
  8342.           continue;
  8343.         }
  8344.       break;
  8345.  
  8346.     case ASHIFT:
  8347.     case LSHIFT:
  8348.       /* If we have (compare (xshift FOO N) (const_int C)) and
  8349.          the high order N bits of FOO (N+1 if an inequality comparison)
  8350.          are not significant, we can do this by comparing FOO with C
  8351.          shifted right N bits so long as the low-order N bits of C are
  8352.          zero.  */
  8353.       if (GET_CODE (XEXP (op0, 1)) == CONST_INT
  8354.           && INTVAL (XEXP (op0, 1)) >= 0
  8355.           && ((INTVAL (XEXP (op0, 1)) + ! equality_comparison_p)
  8356.           < HOST_BITS_PER_WIDE_INT)
  8357.           && ((const_op
  8358.            &  ((HOST_WIDE_INT) 1 << INTVAL (XEXP (op0, 1))) - 1) == 0)
  8359.           && mode_width <= HOST_BITS_PER_WIDE_INT
  8360.           && (significant_bits (XEXP (op0, 0), mode)
  8361.           & ~ (mask >> (INTVAL (XEXP (op0, 1))
  8362.                 + ! equality_comparison_p))) == 0)
  8363.         {
  8364.           const_op >>= INTVAL (XEXP (op0, 1));
  8365.           op1 = GEN_INT (const_op);
  8366.           op0 = XEXP (op0, 0);
  8367.           continue;
  8368.         }
  8369.  
  8370.       /* If we are doing a sign bit comparison, it means we are testing
  8371.          a particular bit.  Convert it to the appropriate AND.  */
  8372.       if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8373.           && mode_width <= HOST_BITS_PER_WIDE_INT)
  8374.         {
  8375.           op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
  8376.                         ((HOST_WIDE_INT) 1
  8377.                          << (mode_width - 1
  8378.                          - INTVAL (XEXP (op0, 1)))));
  8379.           code = (code == LT ? NE : EQ);
  8380.           continue;
  8381.         }
  8382.  
  8383.       /* If this an equality comparison with zero and we are shifting
  8384.          the low bit to the sign bit, we can convert this to an AND of the
  8385.          low-order bit.  */
  8386.       if (const_op == 0 && equality_comparison_p
  8387.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8388.           && INTVAL (XEXP (op0, 1)) == mode_width - 1)
  8389.         {
  8390.           op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
  8391.                         (HOST_WIDE_INT) 1);
  8392.           continue;
  8393.         }
  8394.       break;
  8395.  
  8396.     case ASHIFTRT:
  8397.       /* If this is an equality comparison with zero, we can do this
  8398.          as a logical shift, which might be much simpler.  */
  8399.       if (equality_comparison_p && const_op == 0
  8400.           && GET_CODE (XEXP (op0, 1)) == CONST_INT)
  8401.         {
  8402.           op0 = simplify_shift_const (NULL_RTX, LSHIFTRT, mode,
  8403.                       XEXP (op0, 0),
  8404.                       INTVAL (XEXP (op0, 1)));
  8405.           continue;
  8406.         }
  8407.  
  8408.       /* If OP0 is a sign extension and CODE is not an unsigned comparison,
  8409.          do the comparison in a narrower mode.  */
  8410.       if (! unsigned_comparison_p
  8411.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8412.           && GET_CODE (XEXP (op0, 0)) == ASHIFT
  8413.           && XEXP (op0, 1) == XEXP (XEXP (op0, 0), 1)
  8414.           && (tmode = mode_for_size (mode_width - INTVAL (XEXP (op0, 1)),
  8415.                      MODE_INT, 1)) != BLKmode
  8416.           && ((unsigned HOST_WIDE_INT) const_op <= GET_MODE_MASK (tmode)
  8417.           || ((unsigned HOST_WIDE_INT) - const_op
  8418.               <= GET_MODE_MASK (tmode))))
  8419.         {
  8420.           op0 = gen_lowpart_for_combine (tmode, XEXP (XEXP (op0, 0), 0));
  8421.           continue;
  8422.         }
  8423.  
  8424.       /* ... fall through ... */
  8425.     case LSHIFTRT:
  8426.       /* If we have (compare (xshiftrt FOO N) (const_int C)) and
  8427.          the low order N bits of FOO are not significant, we can do this
  8428.          by comparing FOO with C shifted left N bits so long as no
  8429.          overflow occurs.  */
  8430.       if (GET_CODE (XEXP (op0, 1)) == CONST_INT
  8431.           && INTVAL (XEXP (op0, 1)) >= 0
  8432.           && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT
  8433.           && mode_width <= HOST_BITS_PER_WIDE_INT
  8434.           && (significant_bits (XEXP (op0, 0), mode)
  8435.           & (((HOST_WIDE_INT) 1 << INTVAL (XEXP (op0, 1))) - 1)) == 0
  8436.           && (const_op == 0
  8437.           || (floor_log2 (const_op) + INTVAL (XEXP (op0, 1))
  8438.               < mode_width)))
  8439.         {
  8440.           const_op <<= INTVAL (XEXP (op0, 1));
  8441.           op1 = GEN_INT (const_op);
  8442.           op0 = XEXP (op0, 0);
  8443.           continue;
  8444.         }
  8445.  
  8446.       /* If we are using this shift to extract just the sign bit, we
  8447.          can replace this with an LT or GE comparison.  */
  8448.       if (const_op == 0
  8449.           && (equality_comparison_p || sign_bit_comparison_p)
  8450.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8451.           && INTVAL (XEXP (op0, 1)) == mode_width - 1)
  8452.         {
  8453.           op0 = XEXP (op0, 0);
  8454.           code = (code == NE || code == GT ? LT : GE);
  8455.           continue;
  8456.         }
  8457.       break;
  8458.     }
  8459.  
  8460.       break;
  8461.     }
  8462.  
  8463.   /* Now make any compound operations involved in this comparison.  Then,
  8464.      check for an outmost SUBREG on OP0 that isn't doing anything or is
  8465.      paradoxical.  The latter case can only occur when it is known that the
  8466.      "extra" bits will be zero.  Therefore, it is safe to remove the SUBREG.
  8467.      We can never remove a SUBREG for a non-equality comparison because the
  8468.      sign bit is in a different place in the underlying object.  */
  8469.  
  8470.   op0 = make_compound_operation (op0, op1 == const0_rtx ? COMPARE : SET);
  8471.   op1 = make_compound_operation (op1, SET);
  8472.  
  8473.   if (GET_CODE (op0) == SUBREG && subreg_lowpart_p (op0)
  8474.       && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
  8475.       && (code == NE || code == EQ)
  8476.       && ((GET_MODE_SIZE (GET_MODE (op0))
  8477.        > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0))))))
  8478.     {
  8479.       op0 = SUBREG_REG (op0);
  8480.       op1 = gen_lowpart_for_combine (GET_MODE (op0), op1);
  8481.     }
  8482.  
  8483.   else if (GET_CODE (op0) == SUBREG && subreg_lowpart_p (op0)
  8484.        && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
  8485.        && (code == NE || code == EQ)
  8486.        && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
  8487.            <= HOST_BITS_PER_WIDE_INT)
  8488.        && (significant_bits (SUBREG_REG (op0), GET_MODE (SUBREG_REG (op0)))
  8489.            & ~ GET_MODE_MASK (GET_MODE (op0))) == 0
  8490.        && (tem = gen_lowpart_for_combine (GET_MODE (SUBREG_REG (op0)),
  8491.                           op1),
  8492.            (significant_bits (tem, GET_MODE (SUBREG_REG (op0)))
  8493.         & ~ GET_MODE_MASK (GET_MODE (op0))) == 0))
  8494.     op0 = SUBREG_REG (op0), op1 = tem;
  8495.  
  8496.   /* We now do the opposite procedure: Some machines don't have compare
  8497.      insns in all modes.  If OP0's mode is an integer mode smaller than a
  8498.      word and we can't do a compare in that mode, see if there is a larger
  8499.      mode for which we can do the compare.  There are a number of cases in
  8500.      which we can use the wider mode.  */
  8501.  
  8502.   mode = GET_MODE (op0);
  8503.   if (mode != VOIDmode && GET_MODE_CLASS (mode) == MODE_INT
  8504.       && GET_MODE_SIZE (mode) < UNITS_PER_WORD
  8505.       && cmp_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
  8506.     for (tmode = GET_MODE_WIDER_MODE (mode);
  8507.      (tmode != VOIDmode
  8508.       && GET_MODE_BITSIZE (tmode) <= HOST_BITS_PER_WIDE_INT);
  8509.      tmode = GET_MODE_WIDER_MODE (tmode))
  8510.       if (cmp_optab->handlers[(int) tmode].insn_code != CODE_FOR_nothing)
  8511.     {
  8512.       /* If the only significant bits in OP0 and OP1 are those in the
  8513.          narrower mode and this is an equality or unsigned comparison,
  8514.          we can use the wider mode.  Similarly for sign-extended
  8515.          values and equality or signed comparisons.  */
  8516.       if (((code == EQ || code == NE
  8517.         || code == GEU || code == GTU || code == LEU || code == LTU)
  8518.            && ((significant_bits (op0, tmode) & ~ GET_MODE_MASK (mode))
  8519.            == 0)
  8520.            && ((significant_bits (op1, tmode) & ~ GET_MODE_MASK (mode))
  8521.            == 0))
  8522.           || ((code == EQ || code == NE
  8523.            || code == GE || code == GT || code == LE || code == LT)
  8524.           && (num_sign_bit_copies (op0, tmode)
  8525.               > GET_MODE_BITSIZE (tmode) - GET_MODE_BITSIZE (mode))
  8526.           && (num_sign_bit_copies (op1, tmode)
  8527.               > GET_MODE_BITSIZE (tmode) - GET_MODE_BITSIZE (mode))))
  8528.         {
  8529.           op0 = gen_lowpart_for_combine (tmode, op0);
  8530.           op1 = gen_lowpart_for_combine (tmode, op1);
  8531.           break;
  8532.         }
  8533.  
  8534.       /* If this is a test for negative, we can make an explicit
  8535.          test of the sign bit.  */
  8536.  
  8537.       if (op1 == const0_rtx && (code == LT || code == GE)
  8538.           && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
  8539.         {
  8540.           op0 = gen_binary (AND, tmode,
  8541.                 gen_lowpart_for_combine (tmode, op0),
  8542.                 GEN_INT ((HOST_WIDE_INT) 1
  8543.                      << (GET_MODE_BITSIZE (mode) - 1)));
  8544.           code = (code == LT) ? NE : EQ;
  8545.           break;
  8546.         }
  8547.     }
  8548.  
  8549.   *pop0 = op0;
  8550.   *pop1 = op1;
  8551.  
  8552.   return code;
  8553. }
  8554.  
  8555. /* Return 1 if we know that X, a comparison operation, is not operating
  8556.    on a floating-point value or is EQ or NE, meaning that we can safely
  8557.    reverse it.  */
  8558.  
  8559. static int
  8560. reversible_comparison_p (x)
  8561.      rtx x;
  8562. {
  8563.   if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
  8564.       || GET_CODE (x) == NE || GET_CODE (x) == EQ)
  8565.     return 1;
  8566.  
  8567.   switch (GET_MODE_CLASS (GET_MODE (XEXP (x, 0))))
  8568.     {
  8569.     case MODE_INT:
  8570.       return 1;
  8571.  
  8572.     case MODE_CC:
  8573.       x = get_last_value (XEXP (x, 0));
  8574.       return (x && GET_CODE (x) == COMPARE
  8575.           && GET_MODE_CLASS (GET_MODE (XEXP (x, 0))) == MODE_INT);
  8576.     }
  8577.  
  8578.   return 0;
  8579. }
  8580.  
  8581. /* Utility function for following routine.  Called when X is part of a value
  8582.    being stored into reg_last_set_value.  Sets reg_last_set_table_tick
  8583.    for each register mentioned.  Similar to mention_regs in cse.c  */
  8584.  
  8585. static void
  8586. update_table_tick (x)
  8587.      rtx x;
  8588. {
  8589.   register enum rtx_code code = GET_CODE (x);
  8590.   register char *fmt = GET_RTX_FORMAT (code);
  8591.   register int i;
  8592.  
  8593.   if (code == REG)
  8594.     {
  8595.       int regno = REGNO (x);
  8596.       int endregno = regno + (regno < FIRST_PSEUDO_REGISTER
  8597.                   ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
  8598.  
  8599.       for (i = regno; i < endregno; i++)
  8600.     reg_last_set_table_tick[i] = label_tick;
  8601.  
  8602.       return;
  8603.     }
  8604.   
  8605.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  8606.     /* Note that we can't have an "E" in values stored; see
  8607.        get_last_value_validate.  */
  8608.     if (fmt[i] == 'e')
  8609.       update_table_tick (XEXP (x, i));
  8610. }
  8611.  
  8612. /* Record that REG is set to VALUE in insn INSN.  If VALUE is zero, we
  8613.    are saying that the register is clobbered and we no longer know its
  8614.    value.  If INSN is zero, don't update reg_last_set; this call is normally
  8615.    done with VALUE also zero to invalidate the register.  */
  8616.  
  8617. static void
  8618. record_value_for_reg (reg, insn, value)
  8619.      rtx reg;
  8620.      rtx insn;
  8621.      rtx value;
  8622. {
  8623.   int regno = REGNO (reg);
  8624.   int endregno = regno + (regno < FIRST_PSEUDO_REGISTER
  8625.               ? HARD_REGNO_NREGS (regno, GET_MODE (reg)) : 1);
  8626.   int i;
  8627.  
  8628.   /* If VALUE contains REG and we have a previous value for REG, substitute
  8629.      the previous value.  */
  8630.   if (value && insn && reg_overlap_mentioned_p (reg, value))
  8631.     {
  8632.       rtx tem;
  8633.  
  8634.       /* Set things up so get_last_value is allowed to see anything set up to
  8635.      our insn.  */
  8636.       subst_low_cuid = INSN_CUID (insn);
  8637.       tem = get_last_value (reg);      
  8638.  
  8639.       if (tem)
  8640.     value = replace_rtx (copy_rtx (value), reg, tem);
  8641.     }
  8642.  
  8643.   /* For each register modified, show we don't know its value, that
  8644.      its value has been updated, and that we don't know the location of
  8645.      the death of the register.  */
  8646.   for (i = regno; i < endregno; i ++)
  8647.     {
  8648.       if (insn)
  8649.     reg_last_set[i] = insn;
  8650.       reg_last_set_value[i] = 0;
  8651.       reg_last_death[i] = 0;
  8652.     }
  8653.  
  8654.   /* Mark registers that are being referenced in this value.  */
  8655.   if (value)
  8656.     update_table_tick (value);
  8657.  
  8658.   /* Now update the status of each register being set.
  8659.      If someone is using this register in this block, set this register
  8660.      to invalid since we will get confused between the two lives in this
  8661.      basic block.  This makes using this register always invalid.  In cse, we
  8662.      scan the table to invalidate all entries using this register, but this
  8663.      is too much work for us.  */
  8664.  
  8665.   for (i = regno; i < endregno; i++)
  8666.     {
  8667.       reg_last_set_label[i] = label_tick;
  8668.       if (value && reg_last_set_table_tick[i] == label_tick)
  8669.     reg_last_set_invalid[i] = 1;
  8670.       else
  8671.     reg_last_set_invalid[i] = 0;
  8672.     }
  8673.  
  8674.   /* The value being assigned might refer to X (like in "x++;").  In that
  8675.      case, we must replace it with (clobber (const_int 0)) to prevent
  8676.      infinite loops.  */
  8677.   if (value && ! get_last_value_validate (&value,
  8678.                       reg_last_set_label[regno], 0))
  8679.     {
  8680.       value = copy_rtx (value);
  8681.       if (! get_last_value_validate (&value, reg_last_set_label[regno], 1))
  8682.     value = 0;
  8683.     }
  8684.  
  8685.   /* For the main register being modified, update the value.  */
  8686.   reg_last_set_value[regno] = value;
  8687.  
  8688. }
  8689.  
  8690. /* Used for communication between the following two routines.  */
  8691. static rtx record_dead_insn;
  8692.  
  8693. /* Called via note_stores from record_dead_and_set_regs to handle one
  8694.    SET or CLOBBER in an insn.  */
  8695.  
  8696. #ifdef MPW
  8697. #pragma segment COMB04
  8698. #endif
  8699.  
  8700. static void
  8701. record_dead_and_set_regs_1 (dest, setter)
  8702.      rtx dest, setter;
  8703. {
  8704.   if (GET_CODE (dest) == REG)
  8705.     {
  8706.       /* If we are setting the whole register, we know its value.  Otherwise
  8707.      show that we don't know the value.  We can handle SUBREG in
  8708.      some cases.  */
  8709.       if (GET_CODE (setter) == SET && dest == SET_DEST (setter))
  8710.     record_value_for_reg (dest, record_dead_insn, SET_SRC (setter));
  8711.       else if (GET_CODE (setter) == SET
  8712.            && GET_CODE (SET_DEST (setter)) == SUBREG
  8713.            && SUBREG_REG (SET_DEST (setter)) == dest
  8714.            && subreg_lowpart_p (SET_DEST (setter)))
  8715.     record_value_for_reg (dest, record_dead_insn,
  8716.                   gen_lowpart_for_combine (GET_MODE (dest),
  8717.                                SET_SRC (setter)));
  8718.       else
  8719.     record_value_for_reg (dest, record_dead_insn, NULL_RTX);
  8720.     }
  8721.   else if (GET_CODE (dest) == MEM
  8722.        /* Ignore pushes, they clobber nothing.  */
  8723.        && ! push_operand (dest, GET_MODE (dest)))
  8724.     mem_last_set = INSN_CUID (record_dead_insn);
  8725. }
  8726.  
  8727. /* Update the records of when each REG was most recently set or killed
  8728.    for the things done by INSN.  This is the last thing done in processing
  8729.    INSN in the combiner loop.
  8730.  
  8731.    We update reg_last_set, reg_last_set_value, reg_last_death, and also the
  8732.    similar information mem_last_set (which insn most recently modified memory)
  8733.    and last_call_cuid (which insn was the most recent subroutine call).  */
  8734.  
  8735. static void
  8736. record_dead_and_set_regs (insn)
  8737.      rtx insn;
  8738. {
  8739.   register rtx link;
  8740.   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  8741.     {
  8742.       if (REG_NOTE_KIND (link) == REG_DEAD)
  8743.     reg_last_death[REGNO (XEXP (link, 0))] = insn;
  8744.       else if (REG_NOTE_KIND (link) == REG_INC)
  8745.     record_value_for_reg (XEXP (link, 0), insn, NULL_RTX);
  8746.     }
  8747.  
  8748.   if (GET_CODE (insn) == CALL_INSN)
  8749.     last_call_cuid = mem_last_set = INSN_CUID (insn);
  8750.  
  8751.   record_dead_insn = insn;
  8752.   note_stores (PATTERN (insn), record_dead_and_set_regs_1);
  8753. }
  8754.  
  8755. /* Utility routine for the following function.  Verify that all the registers
  8756.    mentioned in *LOC are valid when *LOC was part of a value set when
  8757.    label_tick == TICK.  Return 0 if some are not.
  8758.  
  8759.    If REPLACE is non-zero, replace the invalid reference with
  8760.    (clobber (const_int 0)) and return 1.  This replacement is useful because
  8761.    we often can get useful information about the form of a value (e.g., if
  8762.    it was produced by a shift that always produces -1 or 0) even though
  8763.    we don't know exactly what registers it was produced from.  */
  8764.  
  8765. static int
  8766. get_last_value_validate (loc, tick, replace)
  8767.      rtx *loc;
  8768.      int tick;
  8769.      int replace;
  8770. {
  8771.   rtx x = *loc;
  8772.   char *fmt = GET_RTX_FORMAT (GET_CODE (x));
  8773.   int len = GET_RTX_LENGTH (GET_CODE (x));
  8774.   int i;
  8775.  
  8776.   if (GET_CODE (x) == REG)
  8777.     {
  8778.       int regno = REGNO (x);
  8779.       int endregno = regno + (regno < FIRST_PSEUDO_REGISTER
  8780.                   ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
  8781.       int j;
  8782.  
  8783.       for (j = regno; j < endregno; j++)
  8784.     if (reg_last_set_invalid[j]
  8785.         /* If this is a pseudo-register that was only set once, it is
  8786.            always valid.  */
  8787.         || (! (regno >= FIRST_PSEUDO_REGISTER && reg_n_sets[regno] == 1)
  8788.         && reg_last_set_label[j] > tick))
  8789.       {
  8790.         if (replace)
  8791.           *loc = gen_rtx (CLOBBER, GET_MODE (x), const0_rtx);
  8792.         return replace;
  8793.       }
  8794.  
  8795.       return 1;
  8796.     }
  8797.  
  8798.   for (i = 0; i < len; i++)
  8799.     if ((fmt[i] == 'e'
  8800.      && get_last_value_validate (&XEXP (x, i), tick, replace) == 0)
  8801.     /* Don't bother with these.  They shouldn't occur anyway.  */
  8802.     || fmt[i] == 'E')
  8803.       return 0;
  8804.  
  8805.   /* If we haven't found a reason for it to be invalid, it is valid.  */
  8806.   return 1;
  8807. }
  8808.  
  8809. /* Get the last value assigned to X, if known.  Some registers
  8810.    in the value may be replaced with (clobber (const_int 0)) if their value
  8811.    is known longer known reliably.  */
  8812.  
  8813. static rtx
  8814. get_last_value (x)
  8815.      rtx x;
  8816. {
  8817.   int regno;
  8818.   rtx value;
  8819.  
  8820.   /* If this is a non-paradoxical SUBREG, get the value of its operand and
  8821.      then convert it to the desired mode.  If this is a paradoxical SUBREG,
  8822.      we cannot predict what values the "extra" bits might have. */
  8823.   if (GET_CODE (x) == SUBREG
  8824.       && subreg_lowpart_p (x)
  8825.       && (GET_MODE_SIZE (GET_MODE (x))
  8826.       <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  8827.       && (value = get_last_value (SUBREG_REG (x))) != 0)
  8828.     return gen_lowpart_for_combine (GET_MODE (x), value);
  8829.  
  8830.   if (GET_CODE (x) != REG)
  8831.     return 0;
  8832.  
  8833.   regno = REGNO (x);
  8834.   value = reg_last_set_value[regno];
  8835.  
  8836.   /* If we don't have a value or if it isn't for this basic block, return 0. */
  8837.  
  8838.   if (value == 0
  8839.       || (reg_n_sets[regno] != 1
  8840.       && (reg_last_set_label[regno] != label_tick)))
  8841.     return 0;
  8842.  
  8843.   /* If the value was set in a later insn that the ones we are processing,
  8844.      we can't use it even if the register was only set once, but make a quick
  8845.      check to see if the previous insn set it to something.  This is commonly
  8846.      the case when the same pseudo is used by repeated insns.  */
  8847.  
  8848.   if (INSN_CUID (reg_last_set[regno]) >= subst_low_cuid)
  8849.     {
  8850.       rtx insn, set;
  8851.  
  8852.       for (insn = prev_nonnote_insn (subst_insn);
  8853.        insn && INSN_CUID (insn) >= subst_low_cuid;
  8854.        insn = prev_nonnote_insn (insn))
  8855.     ;
  8856.  
  8857.       if (insn
  8858.       && (set = single_set (insn)) != 0
  8859.       && rtx_equal_p (SET_DEST (set), x))
  8860.     {
  8861.       value = SET_SRC (set);
  8862.  
  8863.       /* Make sure that VALUE doesn't reference X.  Replace any
  8864.          expliit references with a CLOBBER.  If there are any remaining
  8865.          references (rare), don't use the value.  */
  8866.  
  8867.       if (reg_mentioned_p (x, value))
  8868.         value = replace_rtx (copy_rtx (value), x,
  8869.                  gen_rtx (CLOBBER, GET_MODE (x), const0_rtx));
  8870.  
  8871.       if (reg_overlap_mentioned_p (x, value))
  8872.         return 0;
  8873.     }
  8874.       else
  8875.     return 0;
  8876.     }
  8877.  
  8878.   /* If the value has all its registers valid, return it.  */
  8879.   if (get_last_value_validate (&value, reg_last_set_label[regno], 0))
  8880.     return value;
  8881.  
  8882.   /* Otherwise, make a copy and replace any invalid register with
  8883.      (clobber (const_int 0)).  If that fails for some reason, return 0.  */
  8884.  
  8885.   value = copy_rtx (value);
  8886.   if (get_last_value_validate (&value, reg_last_set_label[regno], 1))
  8887.     return value;
  8888.  
  8889.   return 0;
  8890. }
  8891.  
  8892. /* Return nonzero if expression X refers to a REG or to memory
  8893.    that is set in an instruction more recent than FROM_CUID.  */
  8894.  
  8895. static int
  8896. use_crosses_set_p (x, from_cuid)
  8897.      register rtx x;
  8898.      int from_cuid;
  8899. {
  8900.   register char *fmt;
  8901.   register int i;
  8902.   register enum rtx_code code = GET_CODE (x);
  8903.  
  8904.   if (code == REG)
  8905.     {
  8906.       register int regno = REGNO (x);
  8907. #ifdef PUSH_ROUNDING
  8908.       /* Don't allow uses of the stack pointer to be moved,
  8909.      because we don't know whether the move crosses a push insn.  */
  8910.       if (regno == STACK_POINTER_REGNUM)
  8911.     return 1;
  8912. #endif
  8913.       return (reg_last_set[regno]
  8914.           && INSN_CUID (reg_last_set[regno]) > from_cuid);
  8915.     }
  8916.  
  8917.   if (code == MEM && mem_last_set > from_cuid)
  8918.     return 1;
  8919.  
  8920.   fmt = GET_RTX_FORMAT (code);
  8921.  
  8922.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  8923.     {
  8924.       if (fmt[i] == 'E')
  8925.     {
  8926.       register int j;
  8927.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  8928.         if (use_crosses_set_p (XVECEXP (x, i, j), from_cuid))
  8929.           return 1;
  8930.     }
  8931.       else if (fmt[i] == 'e'
  8932.            && use_crosses_set_p (XEXP (x, i), from_cuid))
  8933.     return 1;
  8934.     }
  8935.   return 0;
  8936. }
  8937.  
  8938. /* Define three variables used for communication between the following
  8939.    routines.  */
  8940.  
  8941. static int reg_dead_regno, reg_dead_endregno;
  8942. static int reg_dead_flag;
  8943.  
  8944. /* Function called via note_stores from reg_dead_at_p.
  8945.  
  8946.    If DEST is within [reg_dead_rengno, reg_dead_endregno), set 
  8947.    reg_dead_flag to 1 if X is a CLOBBER and to -1 it is a SET.  */
  8948.  
  8949. static void
  8950. reg_dead_at_p_1 (dest, x)
  8951.      rtx dest;
  8952.      rtx x;
  8953. {
  8954.   int regno, endregno;
  8955.  
  8956.   if (GET_CODE (dest) != REG)
  8957.     return;
  8958.  
  8959.   regno = REGNO (dest);
  8960.   endregno = regno + (regno < FIRST_PSEUDO_REGISTER 
  8961.               ? HARD_REGNO_NREGS (regno, GET_MODE (dest)) : 1);
  8962.  
  8963.   if (reg_dead_endregno > regno && reg_dead_regno < endregno)
  8964.     reg_dead_flag = (GET_CODE (x) == CLOBBER) ? 1 : -1;
  8965. }
  8966.  
  8967. /* Return non-zero if REG is known to be dead at INSN.
  8968.  
  8969.    We scan backwards from INSN.  If we hit a REG_DEAD note or a CLOBBER
  8970.    referencing REG, it is dead.  If we hit a SET referencing REG, it is
  8971.    live.  Otherwise, see if it is live or dead at the start of the basic
  8972.    block we are in.  */
  8973.  
  8974. static int
  8975. reg_dead_at_p (reg, insn)
  8976.      rtx reg;
  8977.      rtx insn;
  8978. {
  8979.   int block, i;
  8980.  
  8981.   /* Set variables for reg_dead_at_p_1.  */
  8982.   reg_dead_regno = REGNO (reg);
  8983.   reg_dead_endregno = reg_dead_regno + (reg_dead_regno < FIRST_PSEUDO_REGISTER
  8984.                     ? HARD_REGNO_NREGS (reg_dead_regno,
  8985.                                 GET_MODE (reg))
  8986.                     : 1);
  8987.  
  8988.   reg_dead_flag = 0;
  8989.  
  8990.   /* Scan backwards until we find a REG_DEAD note, SET, CLOBBER, label, or
  8991.      beginning of function.  */
  8992.   for (; insn && GET_CODE (insn) != CODE_LABEL;
  8993.        insn = prev_nonnote_insn (insn))
  8994.     {
  8995.       note_stores (PATTERN (insn), reg_dead_at_p_1);
  8996.       if (reg_dead_flag)
  8997.     return reg_dead_flag == 1 ? 1 : 0;
  8998.  
  8999.       if (find_regno_note (insn, REG_DEAD, reg_dead_regno))
  9000.     return 1;
  9001.     }
  9002.  
  9003.   /* Get the basic block number that we were in.  */
  9004.   if (insn == 0)
  9005.     block = 0;
  9006.   else
  9007.     {
  9008.       for (block = 0; block < n_basic_blocks; block++)
  9009.     if (insn == basic_block_head[block])
  9010.       break;
  9011.  
  9012.       if (block == n_basic_blocks)
  9013.     return 0;
  9014.     }
  9015.  
  9016.   for (i = reg_dead_regno; i < reg_dead_endregno; i++)
  9017.     if (basic_block_live_at_start[block][i / REGSET_ELT_BITS]
  9018.     & ((REGSET_ELT_TYPE) 1 << (i % REGSET_ELT_BITS)))
  9019.       return 0;
  9020.  
  9021.   return 1;
  9022. }
  9023.  
  9024. /* Remove register number REGNO from the dead registers list of INSN.
  9025.  
  9026.    Return the note used to record the death, if there was one.  */
  9027.  
  9028. rtx
  9029. remove_death (regno, insn)
  9030.      int regno;
  9031.      rtx insn;
  9032. {
  9033.   register rtx note = find_regno_note (insn, REG_DEAD, regno);
  9034.  
  9035.   if (note)
  9036.     {
  9037.       reg_n_deaths[regno]--;
  9038.       remove_note (insn, note);
  9039.     }
  9040.  
  9041.   return note;
  9042. }
  9043.  
  9044. /* For each register (hardware or pseudo) used within expression X, if its
  9045.    death is in an instruction with cuid between FROM_CUID (inclusive) and
  9046.    TO_INSN (exclusive), put a REG_DEAD note for that register in the
  9047.    list headed by PNOTES. 
  9048.  
  9049.    This is done when X is being merged by combination into TO_INSN.  These
  9050.    notes will then be distributed as needed.  */
  9051.  
  9052. static void
  9053. move_deaths (x, from_cuid, to_insn, pnotes)
  9054.      rtx x;
  9055.      int from_cuid;
  9056.      rtx to_insn;
  9057.      rtx *pnotes;
  9058. {
  9059.   register char *fmt;
  9060.   register int len, i;
  9061.   register enum rtx_code code = GET_CODE (x);
  9062.  
  9063.   if (code == REG)
  9064.     {
  9065.       register int regno = REGNO (x);
  9066.       register rtx where_dead = reg_last_death[regno];
  9067.  
  9068.       if (where_dead && INSN_CUID (where_dead) >= from_cuid
  9069.       && INSN_CUID (where_dead) < INSN_CUID (to_insn))
  9070.     {
  9071.       rtx note = remove_death (regno, reg_last_death[regno]);
  9072.  
  9073.       /* It is possible for the call above to return 0.  This can occur
  9074.          when reg_last_death points to I2 or I1 that we combined with.
  9075.          In that case make a new note.  */
  9076.  
  9077.       if (note)
  9078.         {
  9079.           XEXP (note, 1) = *pnotes;
  9080.           *pnotes = note;
  9081.         }
  9082.       else
  9083.         *pnotes = gen_rtx (EXPR_LIST, REG_DEAD, x, *pnotes);
  9084.  
  9085.       reg_n_deaths[regno]++;
  9086.     }
  9087.  
  9088.       return;
  9089.     }
  9090.  
  9091.   else if (GET_CODE (x) == SET)
  9092.     {
  9093.       rtx dest = SET_DEST (x);
  9094.  
  9095.       move_deaths (SET_SRC (x), from_cuid, to_insn, pnotes);
  9096.  
  9097.       /* In the case of a ZERO_EXTRACT, a STRICT_LOW_PART, or a SUBREG
  9098.      that accesses one word of a multi-word item, some
  9099.      piece of everything register in the expression is used by
  9100.      this insn, so remove any old death.  */
  9101.  
  9102.       if (GET_CODE (dest) == ZERO_EXTRACT
  9103.       || GET_CODE (dest) == STRICT_LOW_PART
  9104.       || (GET_CODE (dest) == SUBREG
  9105.           && (((GET_MODE_SIZE (GET_MODE (dest))
  9106.             + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
  9107.           == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
  9108.                + UNITS_PER_WORD - 1) / UNITS_PER_WORD))))
  9109.     {
  9110.       move_deaths (dest, from_cuid, to_insn, pnotes);
  9111.       return;
  9112.     }
  9113.  
  9114.       /* If this is some other SUBREG, we know it replaces the entire
  9115.      value, so use that as the destination.  */
  9116.       if (GET_CODE (dest) == SUBREG)
  9117.     dest = SUBREG_REG (dest);
  9118.  
  9119.       /* If this is a MEM, adjust deaths of anything used in the address.
  9120.      For a REG (the only other possibility), the entire value is
  9121.      being replaced so the old value is not used in this insn.  */
  9122.  
  9123.       if (GET_CODE (dest) == MEM)
  9124.     move_deaths (XEXP (dest, 0), from_cuid, to_insn, pnotes);
  9125.       return;
  9126.     }
  9127.  
  9128.   else if (GET_CODE (x) == CLOBBER)
  9129.     return;
  9130.  
  9131.   len = GET_RTX_LENGTH (code);
  9132.   fmt = GET_RTX_FORMAT (code);
  9133.  
  9134.   for (i = 0; i < len; i++)
  9135.     {
  9136.       if (fmt[i] == 'E')
  9137.     {
  9138.       register int j;
  9139.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  9140.         move_deaths (XVECEXP (x, i, j), from_cuid, to_insn, pnotes);
  9141.     }
  9142.       else if (fmt[i] == 'e')
  9143.     move_deaths (XEXP (x, i), from_cuid, to_insn, pnotes);
  9144.     }
  9145. }
  9146.  
  9147. /* Return 1 if X is the target of a bit-field assignment in BODY, the
  9148.    pattern of an insn.  X must be a REG.  */
  9149.  
  9150. static int
  9151. reg_bitfield_target_p (x, body)
  9152.      rtx x;
  9153.      rtx body;
  9154. {
  9155.   int i;
  9156.  
  9157.   if (GET_CODE (body) == SET)
  9158.     {
  9159.       rtx dest = SET_DEST (body);
  9160.       rtx target;
  9161.       int regno, tregno, endregno, endtregno;
  9162.  
  9163.       if (GET_CODE (dest) == ZERO_EXTRACT)
  9164.     target = XEXP (dest, 0);
  9165.       else if (GET_CODE (dest) == STRICT_LOW_PART)
  9166.     target = SUBREG_REG (XEXP (dest, 0));
  9167.       else
  9168.     return 0;
  9169.  
  9170.       if (GET_CODE (target) == SUBREG)
  9171.     target = SUBREG_REG (target);
  9172.  
  9173.       if (GET_CODE (target) != REG)
  9174.     return 0;
  9175.  
  9176.       tregno = REGNO (target), regno = REGNO (x);
  9177.       if (tregno >= FIRST_PSEUDO_REGISTER || regno >= FIRST_PSEUDO_REGISTER)
  9178.     return target == x;
  9179.  
  9180.       endtregno = tregno + HARD_REGNO_NREGS (tregno, GET_MODE (target));
  9181.       endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
  9182.  
  9183.       return endregno > tregno && regno < endtregno;
  9184.     }
  9185.  
  9186.   else if (GET_CODE (body) == PARALLEL)
  9187.     for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
  9188.       if (reg_bitfield_target_p (x, XVECEXP (body, 0, i)))
  9189.     return 1;
  9190.  
  9191.   return 0;
  9192. }      
  9193.  
  9194. /* Given a chain of REG_NOTES originally from FROM_INSN, try to place them
  9195.    as appropriate.  I3 and I2 are the insns resulting from the combination
  9196.    insns including FROM (I2 may be zero).
  9197.  
  9198.    ELIM_I2 and ELIM_I1 are either zero or registers that we know will
  9199.    not need REG_DEAD notes because they are being substituted for.  This
  9200.    saves searching in the most common cases.
  9201.  
  9202.    Each note in the list is either ignored or placed on some insns, depending
  9203.    on the type of note.  */
  9204.  
  9205. static void
  9206. distribute_notes (notes, from_insn, i3, i2, elim_i2, elim_i1)
  9207.      rtx notes;
  9208.      rtx from_insn;
  9209.      rtx i3, i2;
  9210.      rtx elim_i2, elim_i1;
  9211. {
  9212.   rtx note, next_note;
  9213.   rtx tem;
  9214.  
  9215.   for (note = notes; note; note = next_note)
  9216.     {
  9217.       rtx place = 0, place2 = 0;
  9218.  
  9219.       /* If this NOTE references a pseudo register, ensure it references
  9220.      the latest copy of that register.  */
  9221.       if (XEXP (note, 0) && GET_CODE (XEXP (note, 0)) == REG
  9222.       && REGNO (XEXP (note, 0)) >= FIRST_PSEUDO_REGISTER)
  9223.     XEXP (note, 0) = regno_reg_rtx[REGNO (XEXP (note, 0))];
  9224.  
  9225.       next_note = XEXP (note, 1);
  9226.       switch (REG_NOTE_KIND (note))
  9227.     {
  9228.     case REG_UNUSED:
  9229.       /* If this register is set or clobbered in I3, put the note there
  9230.          unless there is one already.  */
  9231.       if (reg_set_p (XEXP (note, 0), PATTERN (i3)))
  9232.         {
  9233.           if (! (GET_CODE (XEXP (note, 0)) == REG
  9234.              ? find_regno_note (i3, REG_UNUSED, REGNO (XEXP (note, 0)))
  9235.              : find_reg_note (i3, REG_UNUSED, XEXP (note, 0))))
  9236.         place = i3;
  9237.         }
  9238.       /* Otherwise, if this register is used by I3, then this register
  9239.          now dies here, so we must put a REG_DEAD note here unless there
  9240.          is one already.  */
  9241.       else if (reg_referenced_p (XEXP (note, 0), PATTERN (i3))
  9242.            && ! (GET_CODE (XEXP (note, 0)) == REG
  9243.              ? find_regno_note (i3, REG_DEAD, REGNO (XEXP (note, 0)))
  9244.              : find_reg_note (i3, REG_DEAD, XEXP (note, 0))))
  9245.         {
  9246.           PUT_REG_NOTE_KIND (note, REG_DEAD);
  9247.           place = i3;
  9248.         }
  9249.       break;
  9250.  
  9251.     case REG_EQUAL:
  9252.     case REG_EQUIV:
  9253.     case REG_NONNEG:
  9254.       /* These notes say something about results of an insn.  We can
  9255.          only support them if they used to be on I3 in which case they
  9256.          remain on I3.  Otherwise they are ignored.
  9257.  
  9258.          If the note refers to an expression that is not a constant, we
  9259.          must also ignore the note since we cannot tell whether the
  9260.          equivalence is still true.  It might be possible to do
  9261.          slightly better than this (we only have a problem if I2DEST
  9262.          or I1DEST is present in the expression), but it doesn't
  9263.          seem worth the trouble.  */
  9264.  
  9265.       if (from_insn == i3
  9266.           && (XEXP (note, 0) == 0 || CONSTANT_P (XEXP (note, 0))))
  9267.         place = i3;
  9268.       break;
  9269.  
  9270.     case REG_INC:
  9271.     case REG_NO_CONFLICT:
  9272.     case REG_LABEL:
  9273.       /* These notes say something about how a register is used.  They must
  9274.          be present on any use of the register in I2 or I3.  */
  9275.       if (reg_mentioned_p (XEXP (note, 0), PATTERN (i3)))
  9276.         place = i3;
  9277.  
  9278.       if (i2 && reg_mentioned_p (XEXP (note, 0), PATTERN (i2)))
  9279.         {
  9280.           if (place)
  9281.         place2 = i2;
  9282.           else
  9283.         place = i2;
  9284.         }
  9285.       break;
  9286.  
  9287.     case REG_WAS_0:
  9288.       /* It is too much trouble to try to see if this note is still
  9289.          correct in all situations.  It is better to simply delete it.  */
  9290.       break;
  9291.  
  9292.     case REG_RETVAL:
  9293.       /* If the insn previously containing this note still exists,
  9294.          put it back where it was.  Otherwise move it to the previous
  9295.          insn.  Adjust the corresponding REG_LIBCALL note.  */
  9296.       if (GET_CODE (from_insn) != NOTE)
  9297.         place = from_insn;
  9298.       else
  9299.         {
  9300.           tem = find_reg_note (XEXP (note, 0), REG_LIBCALL, NULL_RTX);
  9301.           place = prev_real_insn (from_insn);
  9302.           if (tem && place)
  9303.         XEXP (tem, 0) = place;
  9304.         }
  9305.       break;
  9306.  
  9307.     case REG_LIBCALL:
  9308.       /* This is handled similarly to REG_RETVAL.  */
  9309.       if (GET_CODE (from_insn) != NOTE)
  9310.         place = from_insn;
  9311.       else
  9312.         {
  9313.           tem = find_reg_note (XEXP (note, 0), REG_RETVAL, NULL_RTX);
  9314.           place = next_real_insn (from_insn);
  9315.           if (tem && place)
  9316.         XEXP (tem, 0) = place;
  9317.         }
  9318.       break;
  9319.  
  9320.     case REG_DEAD:
  9321.       /* If the register is used as an input in I3, it dies there.
  9322.          Similarly for I2, if it is non-zero and adjacent to I3.
  9323.  
  9324.          If the register is not used as an input in either I3 or I2
  9325.          and it is not one of the registers we were supposed to eliminate,
  9326.          there are two possibilities.  We might have a non-adjacent I2
  9327.          or we might have somehow eliminated an additional register
  9328.          from a computation.  For example, we might have had A & B where
  9329.          we discover that B will always be zero.  In this case we will
  9330.          eliminate the reference to A.
  9331.  
  9332.          In both cases, we must search to see if we can find a previous
  9333.          use of A and put the death note there.  */
  9334.  
  9335.       if (reg_referenced_p (XEXP (note, 0), PATTERN (i3)))
  9336.         place = i3;
  9337.       else if (i2 != 0 && next_nonnote_insn (i2) == i3
  9338.            && reg_referenced_p (XEXP (note, 0), PATTERN (i2)))
  9339.         place = i2;
  9340.  
  9341.       if (XEXP (note, 0) == elim_i2 || XEXP (note, 0) == elim_i1)
  9342.         break;
  9343.  
  9344.       /* If the register is used in both I2 and I3 and it dies in I3, 
  9345.          we might have added another reference to it.  If reg_n_refs
  9346.          was 2, bump it to 3.  This has to be correct since the 
  9347.          register must have been set somewhere.  The reason this is
  9348.          done is because local-alloc.c treats 2 references as a 
  9349.          special case.  */
  9350.  
  9351.       if (place == i3 && i2 != 0 && GET_CODE (XEXP (note, 0)) == REG
  9352.           && reg_n_refs[REGNO (XEXP (note, 0))]== 2
  9353.           && reg_referenced_p (XEXP (note, 0), PATTERN (i2)))
  9354.         reg_n_refs[REGNO (XEXP (note, 0))] = 3;
  9355.  
  9356.       if (place == 0)
  9357.         for (tem = prev_nonnote_insn (i3);
  9358.          tem && (GET_CODE (tem) == INSN
  9359.              || GET_CODE (tem) == CALL_INSN);
  9360.          tem = prev_nonnote_insn (tem))
  9361.           {
  9362.         /* If the register is being set at TEM, see if that is all
  9363.            TEM is doing.  If so, delete TEM.  Otherwise, make this
  9364.            into a REG_UNUSED note instead.  */
  9365.         if (reg_set_p (XEXP (note, 0), PATTERN (tem)))
  9366.           {
  9367.             rtx set = single_set (tem);
  9368.  
  9369.             /* Verify that it was the set, and not a clobber that
  9370.                modified the register.  */
  9371.  
  9372.             if (set != 0 && ! side_effects_p (SET_SRC (set))
  9373.             && rtx_equal_p (XEXP (note, 0), SET_DEST (set)))
  9374.               {
  9375.             /* Move the notes and links of TEM elsewhere.
  9376.                This might delete other dead insns recursively. 
  9377.                First set the pattern to something that won't use
  9378.                any register.  */
  9379.  
  9380.             PATTERN (tem) = pc_rtx;
  9381.  
  9382.             distribute_notes (REG_NOTES (tem), tem, tem,
  9383.                       NULL_RTX, NULL_RTX, NULL_RTX);
  9384.             distribute_links (LOG_LINKS (tem));
  9385.  
  9386.             PUT_CODE (tem, NOTE);
  9387.             NOTE_LINE_NUMBER (tem) = NOTE_INSN_DELETED;
  9388.             NOTE_SOURCE_FILE (tem) = 0;
  9389.               }
  9390.             else
  9391.               {
  9392.             PUT_REG_NOTE_KIND (note, REG_UNUSED);
  9393.  
  9394.             /*  If there isn't already a REG_UNUSED note, put one
  9395.                 here.  */
  9396.             if (! find_regno_note (tem, REG_UNUSED,
  9397.                            REGNO (XEXP (note, 0))))
  9398.               place = tem;
  9399.             break;
  9400.               }
  9401.           }
  9402.         else if (reg_referenced_p (XEXP (note, 0), PATTERN (tem)))
  9403.           {
  9404.             place = tem;
  9405.             break;
  9406.           }
  9407.           }
  9408.  
  9409.       /* If the register is set or already dead at PLACE, we needn't do
  9410.          anything with this note if it is still a REG_DEAD note.  
  9411.  
  9412.          Note that we cannot use just `dead_or_set_p' here since we can
  9413.          convert an assignment to a register into a bit-field assignment.
  9414.          Therefore, we must also omit the note if the register is the 
  9415.          target of a bitfield assignment.  */
  9416.          
  9417.       if (place && REG_NOTE_KIND (note) == REG_DEAD)
  9418.         {
  9419.           int regno = REGNO (XEXP (note, 0));
  9420.  
  9421.           if (dead_or_set_p (place, XEXP (note, 0))
  9422.           || reg_bitfield_target_p (XEXP (note, 0), PATTERN (place)))
  9423.         {
  9424.           /* Unless the register previously died in PLACE, clear
  9425.              reg_last_death.  [I no longer understand why this is
  9426.              being done.] */
  9427.           if (reg_last_death[regno] != place)
  9428.             reg_last_death[regno] = 0;
  9429.           place = 0;
  9430.         }
  9431.           else
  9432.         reg_last_death[regno] = place;
  9433.  
  9434.           /* If this is a death note for a hard reg that is occupying
  9435.          multiple registers, ensure that we are still using all
  9436.          parts of the object.  If we find a piece of the object
  9437.          that is unused, we must add a USE for that piece before
  9438.          PLACE and put the appropriate REG_DEAD note on it.
  9439.  
  9440.          An alternative would be to put a REG_UNUSED for the pieces
  9441.          on the insn that set the register, but that can't be done if
  9442.          it is not in the same block.  It is simpler, though less
  9443.          efficient, to add the USE insns.  */
  9444.  
  9445.           if (place && regno < FIRST_PSEUDO_REGISTER
  9446.           && HARD_REGNO_NREGS (regno, GET_MODE (XEXP (note, 0))) > 1)
  9447.         {
  9448.           int endregno
  9449.             = regno + HARD_REGNO_NREGS (regno,
  9450.                         GET_MODE (XEXP (note, 0)));
  9451.           int all_used = 1;
  9452.           int i;
  9453.  
  9454.           for (i = regno; i < endregno; i++)
  9455.             if (! refers_to_regno_p (i, i + 1, PATTERN (place), 0))
  9456.               {
  9457.             rtx piece = gen_rtx (REG, word_mode, i);
  9458.             rtx p;
  9459.  
  9460.             /* See if we already placed a USE note for this
  9461.                register in front of PLACE.  */
  9462.             for (p = place;
  9463.                  GET_CODE (PREV_INSN (p)) == INSN
  9464.                  && GET_CODE (PATTERN (PREV_INSN (p))) == USE;
  9465.                  p = PREV_INSN (p))
  9466.               if (rtx_equal_p (piece,
  9467.                        XEXP (PATTERN (PREV_INSN (p)), 0)))
  9468.                 {
  9469.                   p = 0;
  9470.                   break;
  9471.                 }
  9472.  
  9473.             if (p)
  9474.               {
  9475.                 rtx use_insn
  9476.                   = emit_insn_before (gen_rtx (USE, VOIDmode,
  9477.                                piece),
  9478.                           p);
  9479.                 REG_NOTES (use_insn)
  9480.                   = gen_rtx (EXPR_LIST, REG_DEAD, piece,
  9481.                      REG_NOTES (use_insn));
  9482.               }
  9483.  
  9484.             all_used = 0;
  9485.               }
  9486.  
  9487.           if (! all_used)
  9488.             {
  9489.               /* Put only REG_DEAD notes for pieces that are
  9490.              still used and that are not already dead or set.  */
  9491.  
  9492.               for (i = regno; i < endregno; i++)
  9493.             {
  9494.               rtx piece = gen_rtx (REG, word_mode, i);
  9495.  
  9496.               if (reg_referenced_p (piece, PATTERN (place))
  9497.                   && ! dead_or_set_p (place, piece)
  9498.                   && ! reg_bitfield_target_p (piece,
  9499.                               PATTERN (place)))
  9500.                 REG_NOTES (place) = gen_rtx (EXPR_LIST, REG_DEAD,
  9501.                              piece,
  9502.                              REG_NOTES (place));
  9503.             }
  9504.  
  9505.               place = 0;
  9506.             }
  9507.         }
  9508.         }
  9509.       break;
  9510.  
  9511.     default:
  9512.       /* Any other notes should not be present at this point in the
  9513.          compilation.  */
  9514.       abort ();
  9515.     }
  9516.  
  9517.       if (place)
  9518.     {
  9519.       XEXP (note, 1) = REG_NOTES (place);
  9520.       REG_NOTES (place) = note;
  9521.     }
  9522.       else if ((REG_NOTE_KIND (note) == REG_DEAD
  9523.         || REG_NOTE_KIND (note) == REG_UNUSED)
  9524.            && GET_CODE (XEXP (note, 0)) == REG)
  9525.     reg_n_deaths[REGNO (XEXP (note, 0))]--;
  9526.  
  9527.       if (place2)
  9528.     {
  9529.       if ((REG_NOTE_KIND (note) == REG_DEAD
  9530.            || REG_NOTE_KIND (note) == REG_UNUSED)
  9531.           && GET_CODE (XEXP (note, 0)) == REG)
  9532.         reg_n_deaths[REGNO (XEXP (note, 0))]++;
  9533.  
  9534.       REG_NOTES (place2) = gen_rtx (GET_CODE (note), REG_NOTE_KIND (note),
  9535.                     XEXP (note, 0), REG_NOTES (place2));
  9536.     }
  9537.     }
  9538. }
  9539.  
  9540. /* Similarly to above, distribute the LOG_LINKS that used to be present on
  9541.    I3, I2, and I1 to new locations.  This is also called in one case to
  9542.    add a link pointing at I3 when I3's destination is changed.  */
  9543.  
  9544. static void
  9545. distribute_links (links)
  9546.      rtx links;
  9547. {
  9548.   rtx link, next_link;
  9549.  
  9550.   for (link = links; link; link = next_link)
  9551.     {
  9552.       rtx place = 0;
  9553.       rtx insn;
  9554.       rtx set, reg;
  9555.  
  9556.       next_link = XEXP (link, 1);
  9557.  
  9558.       /* If the insn that this link points to is a NOTE or isn't a single
  9559.      set, ignore it.  In the latter case, it isn't clear what we
  9560.      can do other than ignore the link, since we can't tell which 
  9561.      register it was for.  Such links wouldn't be used by combine
  9562.      anyway.
  9563.  
  9564.      It is not possible for the destination of the target of the link to
  9565.      have been changed by combine.  The only potential of this is if we
  9566.      replace I3, I2, and I1 by I3 and I2.  But in that case the
  9567.      destination of I2 also remains unchanged.  */
  9568.  
  9569.       if (GET_CODE (XEXP (link, 0)) == NOTE
  9570.       || (set = single_set (XEXP (link, 0))) == 0)
  9571.     continue;
  9572.  
  9573.       reg = SET_DEST (set);
  9574.       while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT
  9575.          || GET_CODE (reg) == SIGN_EXTRACT
  9576.          || GET_CODE (reg) == STRICT_LOW_PART)
  9577.     reg = XEXP (reg, 0);
  9578.  
  9579.       /* A LOG_LINK is defined as being placed on the first insn that uses
  9580.      a register and points to the insn that sets the register.  Start
  9581.      searching at the next insn after the target of the link and stop
  9582.      when we reach a set of the register or the end of the basic block.
  9583.  
  9584.      Note that this correctly handles the link that used to point from
  9585.      I3 to I2.  Also note that not much searching is typically done here
  9586.      since most links don't point very far away.  */
  9587.  
  9588.       for (insn = NEXT_INSN (XEXP (link, 0));
  9589.        (insn && GET_CODE (insn) != CODE_LABEL
  9590.         && GET_CODE (PREV_INSN (insn)) != JUMP_INSN);
  9591.        insn = NEXT_INSN (insn))
  9592.     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  9593.         && reg_overlap_mentioned_p (reg, PATTERN (insn)))
  9594.       {
  9595.         if (reg_referenced_p (reg, PATTERN (insn)))
  9596.           place = insn;
  9597.         break;
  9598.       }
  9599.  
  9600.       /* If we found a place to put the link, place it there unless there
  9601.      is already a link to the same insn as LINK at that point.  */
  9602.  
  9603.       if (place)
  9604.     {
  9605.       rtx link2;
  9606.  
  9607.       for (link2 = LOG_LINKS (place); link2; link2 = XEXP (link2, 1))
  9608.         if (XEXP (link2, 0) == XEXP (link, 0))
  9609.           break;
  9610.  
  9611.       if (link2 == 0)
  9612.         {
  9613.           XEXP (link, 1) = LOG_LINKS (place);
  9614.           LOG_LINKS (place) = link;
  9615.         }
  9616.     }
  9617.     }
  9618. }
  9619.  
  9620. void
  9621. dump_combine_stats (file)
  9622.      FILE *file;
  9623. {
  9624.   fprintf
  9625.     (file,
  9626.      ";; Combiner statistics: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n\n",
  9627.      combine_attempts, combine_merges, combine_extras, combine_successes);
  9628. }
  9629.  
  9630. void
  9631. dump_combine_total_stats (file)
  9632.      FILE *file;
  9633. {
  9634.   fprintf
  9635.     (file,
  9636.      "\n;; Combiner totals: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n",
  9637.      total_attempts, total_merges, total_extras, total_successes);
  9638. }
  9639.